Ionic framework 图像未显示在爱奥尼亚的img src中?
我可以在手机中单击照片,但图像不会显示在我的页面上。 我已经安装了官方ionic framework文档中的插件:Ionic framework 图像未显示在爱奥尼亚的img src中?,ionic-framework,ionic2,ionic3,Ionic Framework,Ionic2,Ionic3,我可以在手机中单击照片,但图像不会显示在我的页面上。 我已经安装了官方ionic framework文档中的插件: $ ionic cordova plugin add cordova-plugin-camera $ npm install --save @ionic-native/camera 这是我的代码: getPic() { const options: CameraOptions = { quality: 70, destinationType:
$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera
这是我的代码:
getPic()
{
const options: CameraOptions = {
quality: 70,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
this.myPhoto = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
});
}
我已声明myPhoto:any代码>在我的类中
这就是我展示自己形象的地方:
<ion-content no-bounce padding>
<button ion-button (click)="getPic()">Take A Picture</button>
<p align="center"><img src="{{ myPhoto }}"></p>
</ion-content>
拍一张照片
我不知道我在哪里犯了错误。请帮帮我。谢谢
private OpenCamera(): void{
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
sourceType: this.camera.PictureSourceType.CAMERA,
saveToPhotoAlbum: true
}
this.camera.getPicture(options).then((imageData) => {
this.AddIssueObj.file.push(s);
this.uploadcount=this.AddIssueObj.file.length;
}, (err) => {
// Handle error
});
}
对于HTML:
<ion-scroll scrollX="true" class="m-slider__scroll" scroll-avatar>
<span *ngFor="let v of photoList">
<img src="{{v}}" alt="slider image1" class="m-slider__img" />
</span>
</ion-scroll>
this.myphoto=imagedata;非常感谢您的回答@Rashmi ranjana。但是请告诉我我的代码出了什么问题?为什么它不显示在mypage中?我是否必须更改this.myPhoto='数据:image/jpeg;base64'+图像数据
到thisthis.myphoto=imagedata代码>是。如果我的回答对你有帮助,请投票表决。我所经历的是你不能在爱奥尼亚显示base64图像。是的,没错。我该怎么做?如何显示Base64图像?您不能显示Base64图像。您需要在imagedata中获得的本机路径。你需要在html中显示它。只需更改代码即可。myPhoto='数据:image/jpeg;base64'+图像数据;为此。myphoto=imagedata;