裁剪指定大小的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;

}

posted on 2015-03-09 15:42  Leo1992  阅读(632)  评论(0编辑  收藏  举报

导航