我正在尝试将图像从Gallery显示到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
,则不工作。请帮助 最佳答案
嗨,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>
关于android - Ionic 2中来自画廊的图像未显示在img标签上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47920164/