0
votes

I am having a problem when i crop the image. I am getting my image from documents folder. after cropping my image gets rotated counterclockwise in my uiimageview. please help. This is the method I use for cropping:

- (UIImage *)croppedImage:(CGRect)bounds {
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}

This is the code I use to call the method:

CGRect cropRect = CGRectMake(0,0,imageview.size.width, imageview.size.height)
UIImage *croppedImage = [previewImage croppedImage:cropRect];

Does anyone know why does my image gets rotated?

2

2 Answers

0
votes

The CoreGraphics Image framework doesn't take into account the EXIF data of the image, which is possibly why you're seeing a rotation. Try making the image from a UIImage that is not rotated and it will work fine, or use the CoreGraphics library to parse the EXIF data to compensate.

0
votes

Per the UIImage Class documentation, you can probably use...

+ (UIImage *)imageWithCGImage:(CGImageRef)imageRef 
                        scale:(CGFloat)scale 
                  orientation:(UIImageOrientation)orientation