图片裁剪代码:
-(UIImage*)getSubImage:(UIImage*)image rect:(CGRect)rect
{
CGRect newrect = CGRectMake(0, 0, rect.size.width*2, rect.size.height*2);
CGImageRef subImageRef = CGImageCreateWithImageInRect(image.CGImage, newrect);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, newrect, subImageRef);
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
CGImageRelease(subImageRef);//手动释放
UIGraphicsEndImageContext();
return smallImage;
}
时间: 2024-11-02 03:54:52