简体   繁体   中英

How to crop image to a frame

I have UIImageView with frame size is 200 * 200. I would like to take a picture from camera or library which will fit to that frame.

Do you have any example to do it, like Instagram, Pose app.

Thanks

This method allows you to set a rect that you want to crop on the image, and returns the cropped image. Enjoy your cropping :)

- (UIImage *)cropImage:(UIImage *)image inRect:(CGRect)rect  {
    CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, rect);
    UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);

    return resultImage;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM