Friday, 12 February 2016

Work with Crop Image in Center Ios/iphone

- (UIImage *)imageByCroppingImage:(UIImage *)image toSize:(CGSize)size
{
 // not equivalent to image.size (which depends on the imageOrientation)! 
 double refWidth = CGImageGetWidth(image.CGImage); 
 double refHeight = CGImageGetHeight(image.CGImage);

    double x = (refWidth - size.width) / 2.0;
    double y = (refHeight - size.height) / 2.0; 
 CGRect cropRect = CGRectMake(x, y, size.height, size.width); 
 CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], 
    cropRect); 
 UIImage *cropped = [UIImage imageWithCGImage:imageRef scale:0.0 
  orientation:self.imageOrientation];
    CGImageRelease(imageRef);

    return cropped;
}