图片裁剪

    图片裁剪代码:

-(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;

}


你可能感兴趣的:(图片裁剪)