可以使用如下的代码:
// get part of the image - (UIImage *)getPartOfImage:(UIImage *)img rect:(CGRect)partRect { CGImageRef imageRef = img.CGImage; CGImageRef imagePartRef = CGImageCreateWithImageInRect(imageRef, partRect); UIImage *retImg = [UIImage imageWithCGImage:imagePartRef]; CGImageRelease(imagePartRef); return retImg; }
参考: iphone-common-codes-ccteam源代码