I have a full screen image displayed and what I would like to do is be able to provide a CGRect and using that rect get the area (or the rect) of the full screen image that is within it and create a UIImage of it. How can I accomplish this? I've been racking my brain over this one so any help would be greatly appreciated! Thanks in advance
Asked
Active
Viewed 488 times
1
-
CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; – Yagnesh Dobariya Feb 25 '16 at 05:26
-
Possible duplicate of [Cropping an UIImage](http://stackoverflow.com/questions/158914/cropping-an-uiimage) – JAL Feb 25 '16 at 14:28
1 Answers
1
Try this code !
UIImage* crop(UIImage *image, rect) {
UIGraphicsBeginImageContextWithOptions(rect.size, false, [image scale]);
[image drawAtPoint:CGPointMake(-rect.origin.x, -rect.origin.y)];
cropped_image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return cropped_image;
}

Kumar Utsav
- 2,761
- 4
- 24
- 38