In my application the requirement is to grab image from the photo library or camera and if user wants to crop the image then he should be able to do it but I do not have any idea how to crop the image fetched from camera or photo library.
if you have any idea then share it...
You can crop your image by using UIGraphicsGetImageFromCurrentImageContext
The idea is to draw your image to a cropped graphic context using CoreGraphics and then exporting the current context to an image.
UIGraphicsGetImageFromCurrentImageContext Returns an image based on the contents of the current bitmap-based graphics context.
Return A image object containing the contents of the current bitmap graphics context.
Try something like that :
- (UIImage*)imageCrop:(UIImage *)imageToCrop toRect:(CGRect)rect
{
UIGraphicsBeginImageContext(rect.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGRect clippedRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
CGContextClipToRect( currentContext, clippedRect);
CGRect drawRect = CGRectMake(rect.origin.x, rect.origin.y, imageToCrop.size.width, imageToCrop.size.height);
CGContextDrawImage(currentContext, drawRect, imageToCrop.CGImage);
UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return cropped;
}
hope this helps, Vincent