将base64字符串转换为角度4的图像 [英] Convert base64 string to image in angular 4

查看:64
本文介绍了将base64字符串转换为角度4的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用ng2-image裁剪器裁剪图像时,我有一个要求.但是输出是base64,我想将其转换为图像源,因为我必须将其发送到某些服务器.我已经搜索过,但没有找到与angular 4兼容的任何东西.

I have a requirement where I am cropping the image using ng2-image cropper. But the output is of base64, I want to convert it to image source as I have to send it to some server. I have searched but didn't found anything compatible with angular 4 .

推荐答案

可以通过转换为Blob来完成

it can be done by using conversion to Blob

dataURItoBlob(dataURI) {
    var binary = atob(dataURI.split(',')[1]);
    var array = [];
  for (var i = 0; i < binary.length; i++) {
     array.push(binary.charCodeAt(i));
  }
 return new Blob([new Uint8Array(array)], {
    type: 'image/jpg'
});
}

    enter code here

 var myFile:Blob=this.dataURItoBlob(myDataUri);

这篇关于将base64字符串转换为角度4的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆