Pages

Wednesday, September 18, 2013

Crop Image from an Image in Objective C

Here is the code to cut a piece from an Image or say UIImage

+ (UIImage *)cropImage:(UIImage *)image withArea:(CGRect)rect andScale:(int) scale{
    rect = CGRectMake(rect.origin.x*scale,
                      rect.origin.y*scale,
                      rect.size.width*scale,
                      rect.size.height*scale);
    
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage *img = [UIImage imageWithCGImage:imageRef
                                       scale:scale
                                 orientation:image.imageOrientation];
    CGImageRelease(imageRef);
    return img;
}

No comments:

Post a Comment