裁剪指定大小的UIImage

- (UIImage*)cutOutImageWithRect:(CGRect)rect {

CGImageRef subImageRef = CGImageCreateWithImageInRect(self.CGImage, rect);

CGRect smallBounds = CGRectMake(0, 0, CGImageGetWidth(subImageRef), CGImageGetHeight(subImageRef));

UIGraphicsBeginImageContext(smallBounds.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextDrawImage(context, smallBounds, subImageRef);

UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];

UIGraphicsEndImageContext();

return smallImage;

}

原文地址:https://www.cnblogs.com/leo-92/p/4323740.html