码迷,mamicode.com
首页 > 移动开发 > 详细

iOS使用代码截图

时间:2016-04-16 00:35:55      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

/**
 *  截图代码
 *
 *  @param view 需要截图的view
 *  @param rect 需要截取的区域
 *
 *  @return 返回截取的对象
 */
+ (UIImage *)viewSnapshot:(UIView *)view withInRect:(CGRect)rect
{
    
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,rect);
    image = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    return image;
}

 

iOS使用代码截图

标签:

原文地址:http://www.cnblogs.com/wobuyayi/p/5397255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!