I think this is the easiest way:
CGRect rect = CGRectMake(0.0, 0.0, 320.0, 430.0); CGImageRef tempImage = CGImageCreateWithImageInRect([originalImage CGImage], rect); UIImage *newImage = [UIImage imageWithCGImage:tempImage]; CGImageRelease(tempImage);
But don't forget to clear the image; Orientation before cropping; otherwise, you will get a rotated image after cropping:
-(UIImage *)normalizeImage:(UIImage *)raw { if (raw.imageOrientation == UIImageOrientationUp) return raw; UIGraphicsBeginImageContextWithOptions(raw.size, NO, raw.scale); [raw drawInRect:(CGRect){0, 0, raw.size}]; UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return normalizedImage; }
Denis zarubin
source share