美文网首页
解决用context重绘后image发生翻转问题

解决用context重绘后image发生翻转问题

作者: binkylee | 来源:发表于2016-06-29 17:03 被阅读0次

    - (UIImage*)getSubImage:(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, [self flip:subImageRef]);

    UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];

    UIGraphicsEndImageContext();

    return smallImage;

    }

    - (CGImageRef )flip:(CGImageRef)image{

    CGSize size = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));

    UIGraphicsBeginImageContextWithOptions(size, NO, 0);

    CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, size.width, size.height), image);

    CGImageRef result = [UIGraphicsGetImageFromCurrentImageContext() CGImage];

    UIGraphicsEndImageContext();

    return result;

    }

    相关文章

      网友评论

          本文标题:解决用context重绘后image发生翻转问题

          本文链接:https://www.haomeiwen.com/subject/todxjttx.html