Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting UIImage to CGImage cause rotation of Image

I am trying to crop image by my custom cropper. Not from the UIImagePickerController's. Now for that I am showing the Image captured from Image Picker in a UIImgeView by handling UIImagePicker's delegate:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    imvOriginalImage.image = image;
}

For cropping I have to convert this Image to CGImageRef. The Image is captured in portrait mode. Now when I convert this image in CGImageRef image orientation get changed. Even if I use following:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    //imvOriginalImage.image = image;
    CGImageRef imgRef = [image CGImage];
    UIImage *img = [UIImage imageWithCGImage:imgRef];
    [imvOriginalImage setImage:img];

}

Image Orientation get changed. This happens only for those Image which are captured in portrait mode. Landscape images not have this issue.

  1. Why this is happening?
  2. How to solve this?

Thanks In Advance.

like image 641
Kapil Choubisa Avatar asked Oct 07 '22 17:10

Kapil Choubisa


1 Answers

This is that iPhone camera rotates the image comparing with Home button. It uses EXIF that is meta data of image. See this thread:

iPhone image rotation

like image 165
Saad Avatar answered Oct 12 '22 10:10

Saad