我正在尝试将图像从图库显示到 img 标记.但图像未显示在 img 标记上.但它正在使用 PhotoViewer .下面是我的代码.
I am trying to display image from gallery to img tag. But image not showing on img tag. But it is working with PhotoViewer . below is my code.
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.请帮忙
If I am using sourceType as camera (sourceType: this.camera.PictureSourceType.CAMERA),it also working,it displays image on img tag, But not working on if i use sourceType as sourceType: this.camera.PictureSourceType.PHOTOLIBRARY . Please help
你好,在ios也有同样的问题,我通过执行以下步骤解决了这个问题
Hi have the same problem in ios, I resolve this problem by doing the following step
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>
这篇关于来自画廊的图像未显示在 ionic 2 的 img 标签上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Android 上的数字软键盘Numeric Soft Keyboard on Android(Android 上的数字软键盘)
带有软键盘和“返回"的 EditText按钮EditText with soft keyboard and quot;Backquot; button(带有软键盘和“返回的 EditText按钮)
在 Android 上的应用程序中内置自定义“键盘&quoCustom #39;Keyboard#39; built in an application on Android(在 Android 上的应用程序中内置自定义“键盘)
如何在 Android 的移动网站中强制使用带有数字的How to force keyboard with numbers in mobile website in Android(如何在 Android 的移动网站中强制使用带有数字的键盘)
启动 Activity 时自动弹出键盘Automatic popping up keyboard on start Activity(启动 Activity 时自动弹出键盘)
如何制作 Android EditView“完成"按钮并在单击时How do I make an Android EditView #39;Done#39; button and hide the keyboard when clicked?(如何制作 Android EditView“完成按钮并在单击时隐藏