Currently I'm developing an ionic-framework-mobile-application and I have the problem to correctly make profile-pictures.
I am using the cordovaCamera-plugin and I have to take pictures with the camera or to use pictures from the library. After getting a picture the user should be able to crop the picture to just upload the part, he wants to.
My javascript- / angular-code to take a picture using the camera looks like this:
$scope.takePicture = function () {
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 500,
targetHeight: 500,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function(err) {
// error-handling not done by now
});
};
If I want to choose a picture from the camera the code looks nearly the same, I just change one line to:
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
The problem is now, if I set allowEdit: true, I can take pictures from the camera and crop them on an android device, but an iphone is not able to crop the taken / selected pictures.
If I would set allowEdit: false and just get the picture from cordovaCamera to crop it afterwards with an other function, the picture changes the direction on an android device and the option correctOrientation does not work at all.
I could really need some help to get this problem solved.
Kind regards
rholtermann
you have to use
$cordovaCamera.getPicture(options)
to work for taking a picture or from a library.Here am posting a sample code for camera which worked for me In your controller write the camera code asIn your HTML write the camera button code as
I had troubles with this plugin too and after looking up on the Internet i found out that the camera plugin property
Does not work properly, not returning the cropped image in the promise, but the original (hence not modified) image, check this forum thread
I solved this problem using this plugin alongside with the cordova camera plugin, a pretty neat soluton!