我正在尝试显示从画廊到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: this.camera.PictureSourceType.CAMERA
),它也可以正常工作,它在IMG标签上显示图像,但如果我将SourceType用作sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
,则无效。请帮助
嗨,在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>