问题
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