图像无法显示在Ionic的img src中?

时间:2018-07-21 05:38:47

标签: ionic-framework ionic2 ionic3

我可以单击手机中的照片,但是页面上没有显示图像。 我已经从官方ionic框架文档中安装了插件:

$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera

这是我的代码:

 getPic()
  {
    const options: CameraOptions = {
      quality: 70,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }

    this.camera.getPicture(options).then((imageData) => {         
     this.myPhoto = 'data:image/jpeg;base64,' + imageData;
    }, (err) => {         
    });
  }

我在课堂上声明了myPhoto:any;

这是我展示图片的地方

<ion-content no-bounce padding>   
<button ion-button (click)="getPic()">Take A Picture</button>
<p align="center"><img src="{{ myPhoto }}"></p>
</ion-content>

我不知道我在哪里做错。请帮我。谢谢!

1 个答案:

答案 0 :(得分:1)

 private OpenCamera(): void{
const options: CameraOptions = {
  quality: 50,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE,
  correctOrientation: true,
  sourceType: this.camera.PictureSourceType.CAMERA,
  saveToPhotoAlbum: true
}

this.camera.getPicture(options).then((imageData) => {

  this.AddIssueObj.file.push(s);
  this.uploadcount=this.AddIssueObj.file.length;
}, (err) => {
  // Handle error
});

}

用于HTML:

 <ion-scroll scrollX="true" class="m-slider__scroll" scroll-avatar>
          <span *ngFor="let v of photoList">
            <img src="{{v}}" alt="slider image1" class="m-slider__img" />
          </span>
        </ion-scroll>