3

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.

Community
  • 1
  • 1
Minkle Garg
  • 723
  • 3
  • 9
  • 35

2 Answers2

6

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}.

Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43
  • @ScottCorscadden Corscadden I have tried it but it is get crash and giving the error: -[UIImage fixOrientation]: unrecognized selector sent to instance 0x174b60 – Minkle Garg Mar 27 '12 at 12:12
  • How did you add the category? To truly test it out, you can add the entire contents of the interface and implementation to the very file where you're attempting to `fixOrientation`, above all the other stuff at the top and it should work. Are there any build warnings either? – Scott Corscadden Mar 27 '12 at 12:14
  • If I tried to implement it in my file where I need this ..then it gives the error that: Property imageorientation not found on object of type 'classname'. Do I need to add some framework? – Minkle Garg Mar 27 '12 at 12:19
  • Do you have an import like `#import ` in the header? What object did you pass it? imageOrientation has been a property of UIImage since iOS 2.0. Put a breakpoint on the line right before you pass in origImage, then in the console, type `po origImage` to see if you're actually passing some other class altogether. – Scott Corscadden Mar 27 '12 at 15:26
3
  1. 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,

    import "UIImage+fixOrientation.h"

    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. 
    
chandan
  • 2,453
  • 23
  • 31