【发布时间】:2019-03-23 22:05:11
【问题描述】:
我试图从('@ionic-native/image-picker')获取图像文件 uri 的 base64 字符串(使用'@ionic-native/base64'),但在运行此代码后,图像似乎已损坏。有什么建议吗?
我的html:
<img [src]="base64ImageChosen" *ngIf="base64ImageChosen"/>
选择器选项:
this.pickerOptions = {
maximumImagesCount: 1,
width: 10,
height: 10,
quality: 100,
outputType: 0
};
我的代码:
chooseImage() {
this.imagePicker.getPictures(this.pickerOptions).then((results) => {
for (let i = 0; i < results.length; i++) {
let filePath: string = results[i];
this.base64.encodeFile(filePath)
.then((base64File: string) => {
this.base64ImageChosen = base64File
}, (err) => {
console.log(err);
})
.then((res) =>
this.myForm.patchValue({ imageChosen: this.base64ImageChosen })
)
}
}, (err) => { });
}
【问题讨论】:
-
你正在从服务器获取图像?
-
图片在手机上,我正在使用image-picker插件来获取图片文件的uri
标签: cordova typescript ionic-framework