我正在尝试将图片从图库显示到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
}
使用
捕获的图像this.camera.getPicture(this.options).then((imageData) => {
alert(imageData)
this.photoViewer.show(imageData);
this.captureDataUrl=imageData;
}, (err) => {
// Handle error
});
HTML中的
<img [src]="captureDataUrl" *ngIf="captureDataUrl"/>
如果我使用sourceType作为摄像头(sourceType: this.camera.PictureSourceType.CAMERA
),它也可以工作,它会在img标签上显示图像,但如果我使用sourceType作为sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
则不能正常工作。请帮忙
答案 0 :(得分:4)
你好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();
}
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>