ionic3 <img> tag src [duplicate]

牧云@^-^@ 提交于 2019-12-13 08:16:29

问题


I want take a picture and show it in iphone,I used <img [src]="imagePath"/> in home.html,and in home.ts, add cordova-plugin-camera to take a picture, as following:

const options: CameraOptions = {
 quality: 100,
 destinationType: this.camera.DestinationType.FILE_URI,   //DATA_URL
 encodingType: this.camera.EncodingType.JPEG,
 mediaType: this.camera.MediaType.PICTURE,
 saveToPhotoAlbum: true,                                       
}

this.camera.getPicture(options).then((imageUri) => { //imageData, if DATA_URL

 //if DATA_URL
//let base64Image = 'data:image/jpeg;base64,' + imageData;
//this.imagePath = base64Image;       //the image can be show in screen


//if FILE_URI
this.imagePath = imageUri;});//cannot show image
},(err) => {// Handle error
});

I want to add image url in SQLite, so how can I fix it?


回答1:


import { normalizeURL } from 'ionic-angular';

<img *ngIf="base64Image" src="{{base64Image}}"/> 
   openCamera(pictureSourceType: any) {
let options: CameraOptions = {
  quality: 95,
  destinationType: this.camera.DestinationType.FILE_URI,
  sourceType: pictureSourceType,
  encodingType: this.camera.EncodingType.PNG,
  targetWidth: 400,
  targetHeight: 400,
  saveToPhotoAlbum: true,
  correctOrientation: true
};
this.camera.getPicture(options).then(imageData => {
    if (this.platform.is('ios'))
    this.base64Image = normalizeURL(imageData);
     // IF problem only occur in ios and normalizeURL 
     //not work for you then you can also use 
     //this.base64Image= imageData.replace(/^file:\/\//, '');
  else
    this.base64Image= "data:image/jpeg;base64," + imageData;
}, error => {
  console.log('ERROR -> ' + JSON.stringify(error));
});
}


来源:https://stackoverflow.com/questions/48437580/ionic3-img-tag-src

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!