Fix image orientation + iphone

I am using the camera function in my application and save the images to the document directory after clicking on the photo. Whenever I use images, the orientation of those images changes. So for this I search on stackoverflow and get the solution from this link:

iOS UIImagePickerController - Result of image orientation after loading

But I can't figure out how to use the fix orientation method to get the original orientation of the image. If anyone knows about this please help me.

Thanks everyone.


source to share

2 answers

Add this method somewhere. Then:

UIImage *origImage = <from somewhere>;
UIImage *fixed = [origImage  fixOrientation];


This is a category method, so you can add it to any implementation. It is generally good practice to create a separate file like UIImage+rotationFix.{m,h}




  • Add this category to your project

    UIImage + fixOrientation

    or you can create it manually using the links below.

    [1]: [code for UIImage + FixOrientation.h]

    [2]: [code for UIImage + FixOrientation.m]

    After creating this category, import it into your view controller,

    import "UIImage + fixOrientation.h"

    and implement this delegate UIImagePickerController

    - (void) imagePickerController: (UIImagePickerController *) picker
     didFinishPickingMediaWithInfo: (NSDictionary *) info {
            UIImage *myimage = [info objectForKey: UIImagePickerControllerOriginalImage];
    This fixOrientation method would fix the image orientation in portrait mode. 



All Articles