当然只要你发布你在其他地方找到了答案......
对于那些希望我在这里找到
Cropping an UIImage
我使用的代码基本相同,但我将它添加到UIImage中以使事情变得容易
这对于那些有兴趣
//The .h file
@interface UIImage (crop)
- (UIImage *)crop:(CGRect)rect;
@end
主文件
//The .m file
@implementation UIImage (crop)
- (UIImage *)crop:(CGRect)rect {
if (self.scale > 1.0f) {
rect = CGRectMake(rect.origin.x * self.scale,
rect.origin.y * self.scale,
rect.size.width * self.scale,
rect.size.height * self.scale);
}
CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect);
UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
CGImageRelease(imageRef);
return result;
}
@end
立即致电它很容易。
下面是一个示例:)
UIImage *image = [UIImage imageNamed:@"imgMap.png"];
CGRect frame = CGRectMake (0, 0, 40, 40); //Change this to whatever the frame should be
UIImage *cropped = [image crop:frame];
来源
2012-10-25 04:52:04
Tim