首页 > 解决方案 > 如何将图像的 URL 转换为 base64 (IONIC3)

问题描述

 getimage(Type){
        let options: CameraOptions;
        if (Type == 'camera') {
            options = {
                quality: 100,
                destinationType: this.camera.DestinationType.DATA_URL,
                encodingType: this.camera.EncodingType.JPEG,
                mediaType: this.camera.MediaType.PICTURE

            };
        }
        else if (Type == 'gallery') {
            options = {
                sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
                destinationType: this.camera.DestinationType.DATA_URL,
                encodingType: this.camera.EncodingType.JPEG,
                mediaType: this.camera.MediaType.PICTURE

            };

        }

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

test(input:string)
    {
        let alert = this.alertCtrl.create({
            title: input,
            subTitle: input,
            buttons: ['OK']
        });
        alert.present();

base64Image 没有输出 base64image 我比较输出的结果和转换相同图像的结果 enligne 并且我的代码输出的结果总是与不同的图像相同

标签: angularionic-frameworkionic3

解决方案


推荐阅读