gpt4 book ai didi

ios - Base64 图像损坏 ios

转载 作者:行者123 更新时间:2023-11-29 05:23:51 25 4
gpt4 key购买 nike

我在显示 Base64 图像时遇到问题。

当我以 Base64 格式从相机上传图像时,我可以通过 ionic devapp 显示它,但是当我从 Xcode 构建它并在我的 ios 设备上本地运行它时,图像显示为损坏的图像。

有人能解释一下吗?

谢谢!

private choosePicture() {
const options = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: 0,
correctOrientation: true
};

this.camera.getPicture(options).then((imagePath) => {
let base64Image = 'data:image/jpeg;base64,' + imagePath;

let images = this.createClass.get('imagePath') as FormArray;
images.push(new FormControl(base64Image));
}, (err) => {
if(err !== 'no image selected') {
this.logError(err);
}
});
}

和我的 html

<ion-col col-6 col-md-4 col-xl-3 *ngFor="let image of createClass.controls['imagePath'].value; let i = index">
<img src="{{ image }}"/>
</ion-col>

最佳答案

尝试使用 [src]="image"代替。

您还可以选择使用destinationType:this.camera.DestinationType.FILE_URI。我在使用 Base64 时的经验是,当选择的图像尺寸很大时,我的应用程序崩溃了。

如果您选择使用 file_uri,从 'ionic-Angular' 导入 {normalizeURL};并将其用作 normalizeURL(imagePath);在显示图像之前。

希望这对您有所帮助。

关于ios - Base64 图像损坏 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58380822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com