在UIImage上扩展一个函数 @interface UIImage (Resize) - (UIImage *)croppedImage:(CGRect)bounds; @end @implementation UIImage (Resize) // Returns a copy of this image that is cropped to the given bounds. // The bounds will be adjusted using CGRectIntegral. // This method ignores the image's imageOrientation setting. - (UIImage *)croppedImage:(CGRect)bounds { CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds); UIImage *croppedImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); return croppedImage; } @end
转载于:https://www.cnblogs.com/liuxingzi/archive/2013/04/10/3404337.html