Ionic 2中来自画廊的图像未显示在img标签上

Vin*_*k B 2 android image ionic-framework ionic2 angular

我正在尝试显示图像从画廊到img标签。但是图像未显示在img标签上。但是它正在与PhotoViewer。下面是我的代码。

 options: CameraOptions = {
    quality: 100,
    destinationType: this.camera.DestinationType.FILE_URI,
    encodingType: this.camera.EncodingType.JPEG,
    sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
   //mediaType: this.camera.MediaType.PICTURE
  }
Run Code Online (Sandbox Code Playgroud)

用拍摄的图像

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

  alert(imageData)
  this.photoViewer.show(imageData);
  this.captureDataUrl=imageData;

 }, (err) => {
  // Handle error
 });
Run Code Online (Sandbox Code Playgroud)

在HTML中

<img [src]="captureDataUrl" *ngIf="captureDataUrl"/>
Run Code Online (Sandbox Code Playgroud)

如果我将sourceType用作相机(sourceType: this.camera.PictureSourceType.CAMERA),它也可以工作,它将在img标签上显示图像,但是如果我将sourceType用作,则无法正常工作sourceType: this.camera.PictureSourceType.PHOTOLIBRARY 。请帮忙

小智 5

您好在ios中有相同的问题,我可以通过执行以下步骤来解决此问题

            var options = {
                  quality: 80,
                  allowEdit: true,
                  sourceType: this.camera.PictureSourceType.CAMERA,
                  saveToPhotoAlbum: false,
                  correctOrientation: true,
                  encodingType: this.camera.EncodingType.JPEG,
                  destinationType: this.camera.DestinationType.FILE_URI
                  //encodingType: this.camera.EncodingType.PNG,
                };


                this.camera.getPicture(options).then((imagePath) => {
                      // Special handling for Android library  // 
                      if (this.platform.is('ios')) {
                        this.ImageData = imagePath.replace(/^file:\/\//, '');
                      }
                      else {
                        this.ImageData = imagePath;
                      }
                      this.photos.push(this.ImageData); //if you have to show multiple image
                      this.photos.reverse();
            }
Run Code Online (Sandbox Code Playgroud)

HTML部分

<ion-row>
    <ion-col col-3 *ngFor="let photo of photos; let id = index">
                    <ion-card class="block">
                      <ion-icon name="ios-close-circle-outline" class="deleteIcon" (click)="deletePhoto(id)"></ion-icon>
                      <img [src]="photo" *ngIf="photo" />
                    </ion-card>
    </ion-col>
</ion-row>
Run Code Online (Sandbox Code Playgroud)