Reputation: 751
I am using camera functionality in my application and saving the images in documents directory after clicking the photo. Whenever I use images, the orientation of these images get change. So for it I search on stackoverflow and get the solution in this link:
iOS UIImagePickerController result image orientation after upload
But I am unable to know that how to use the fix orientation method to get the original orientation of the image. If anyone has some idea about it, please help me.
Thanks to all.
Upvotes: 3
Views: 5096
Reputation: 2453
Add this category in your project
UIImage+fixOrientation
or you can create it manually via given below links
[1]:[code for UIImage+FixOrientation.h]
https://github.com/j3r3miah/mapmatic-ios/blob/master/Mapmatic/UIImage+FixOrientation.h
[2]:[code for UIImage+FixOrientation.m]
https://github.com/j3r3miah/mapmatic-ios/blob/master/Mapmatic/UIImage+FixOrientation.m
After creating this category import it in your view controller,
and implement this UIImagePickerController delegate
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
UIImage *myimage = [info objectForKey: UIImagePickerControllerOriginalImage];
myimage=myimage.fixOrientation;
}
This fixOrientation method would fix the image orientation in portrait mode.
Upvotes: 3
Reputation: 2860
Add that method somewhere. Then:
UIImage *origImage = <from somewhere>;
UIImage *fixed = [origImage fixOrientation];
It is a category method, so you can add it to any implementation really. Generally good practice is to create a separate file, say UIImage+rotationFix.{m,h}
.
Upvotes: 6