问题
I am using one camera app. In that after i took photot i need to convert that image to data uri and then have to send to db.
here is what i did :
function opencamer() {
console.log("camer open");
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
$scope.lastPhoto = imageURI;
$scope.imgUrl = "data:image/jpeg;base64," + imageURI;
}, function(err) {
console.err(err);
}, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
saveToPhotoAlbum: false
});
}
but when i sent this $scope.imgUrl
to db. i was not able to get data uri.please help me out how can i solve this.
i am truck more than 3 hr. not able to find solution.please help me out.
thanks
回答1:
Here is the working code
$scope.opencamer= function () {
var options = {
quality: 75,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function (imageURI) {
$scope.lastPhoto = imageURI;
$scope.imgUrl = "data:image/jpeg;base64," + imageURI;
}, function (err) {
// An error occured. Show a message to the user
});
}
send $scope.lastPhoto
to your db instead of $scope.imgUrl
来源:https://stackoverflow.com/questions/43014164/how-to-convert-iamge-to-data-uri-ionic