首页 > 解决方案 > 不允许在 ionic 中加载本地资源

问题描述

我正在尝试在离子中使用相机,它正在单击照片但不显示照片。

getCamera() {
    this.camera.getPicture().then((res)=>{
        this.imageURL = res;
        console.log(this.imageURL);
    }).catch(e=>{
        console.log(e);
    })
}

控制台向我展示

不允许加载本地资源我正在尝试在我的集合组件中使用 imageURL,例如

<img src={{imageURL}} alt="" height="200" width="200" />

标签: ionic-frameworkcordova-plugins

解决方案


Try This

const options: CameraOptions = {
                quality: 90,
                targetWidth: 350,
                targetHeight: 350,
                destinationType: this.camera.DestinationType.DATA_URL,
                encodingType: this.camera.EncodingType.JPEG,
                mediaType: this.camera.MediaType.PICTURE,
                sourceType: this.camera.PictureSourceType.CAMERA, // this.camera.PictureSourceType.SAVEDPHOTOALBUM
                correctOrientation: true,
                allowEdit: true
              };
              this.camera.getPicture(options).then((imageData) => {
                if (imageData) {
                  this.imageURL = 'data:image/jpeg;base64,' + imageData;
                }
              }, (err) => {
              });

推荐阅读