Reputation: 19
I am working on Ionic framework for my hybrid app and using Cordova, I am facing an issue with the pictures taken with camera in both ios and android. When a picture is taken using the device camera in portrait mode it's orientation is being changed automatically. the issue is in both mobile app's (ios & android) and in web (safari & chrome). I used cordova-plugin-camera in application and this is the code in UIImage+CropScaleOrientation.m file in plugin ios code where the rotation for ios is taking place
(UIImage*)imageCorrectedForCaptureOrientation:(UIImageOrientation)imageOrientation
{
float rotation_radians = 0;
bool perpendicular = false;
switch (imageOrientation) {
case UIImageOrientationUp :
rotation_radians = 0.0;
break;
case UIImageOrientationDown:
rotation_radians = M_PI; // don't be scared of radians, if you're reading this, you're good at math
break;
case UIImageOrientationRight:
rotation_radians = M_PI_2;
perpendicular = true;
break;
case UIImageOrientationLeft:
rotation_radians = -M_PI_2;
perpendicular = true;
break;
default:
break;
}
}
this is how i captured the image with device camera
and after selecting (capture), It changes its orientation and in webview also both in chrome(android) and in safari(iphone) picture orientation getting chaned in web also
this is my first stack overflow question so pardon my mistakes, thanks in advance.
Upvotes: 2
Views: 1303
Reputation: 108
For fix it on iOS:
navigator.camera.getPicture(onSuccess, onFail, {
quality: 75,
destinationType: Camera.DestinationType.DATA_URL,
correctOrientation: true,
saveToPhotoAlbum: true
});
The correctOrientation: true
instruction is the key.
Hope this help!
Upvotes: 3