UIimage 剪切

-(UIImage*)getSubImage:(CGRect)rect cgImage:(UIImage*)CGImage
{
    CGImageRef subImageRef = CGImageCreateWithImageInRect(CGImage.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;
}

猜你喜欢

转载自blog.csdn.net/investzhu/article/details/53895374