所以我想实现的是。用户可以选择从相机拍摄图片还是上传图片,但是每当他们上传图片时,图片将是'data:image / jpeg; base64',而我尝试使数据图片成为blob,但是我的blob返回了一个对象而不是URL字符串,所以我该怎么做?我现在拥有的最好的方法是:
this.camera.getPicture(options).then((imageData) => {
this.myphoto = 'data:image/jpeg;base64,' + imageData;
this.b64toBlob(this.myphoto, 'image/jpeg', 512);
}, (err) => {
// Handle error
});
相机代码
和将base64转换器转换为blob
b64toBlob(b64Data: string, contentType: string, sliceSize: number) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''));
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
我如何使它成为Blob链接或将对将图像存储到数据库有用的东西