【问题标题】:Base64 image broken iosBase64图像损坏的ios
【发布时间】:2020-02-11 07:36:40
【问题描述】:

我在显示 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>

【问题讨论】:

    标签: ios typescript ionic-framework base64


    【解决方案1】:

    尝试改用 [src]="image"。

    您也可以选择使用destinationType: this.camera.DestinationType.FILE_URI。使用Base64时,我的体验是我的应用程序在选择的图像大小很大时崩溃。

    如果您选择使用 file_uri, 从“离子角度”导入 {normalizeURL};并将其用作 normalizeURL(imagePath);在显示图像之前。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-06-13
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      相关资源
      最近更新 更多