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

iOS 截图

时间:2015-05-26 10:33:37      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

UIView截图

- (UIImage *)captureView:(UIView *)theView
{
    CGRect rect = theView.frame;
    if ([theView isKindOfClass:[UIScrollView class]]) {
        rect.size = ((UIScrollView *)theView).contentSize;
    }

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [theView.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return img;
}

 

UIScrollview截图

 1 - (UIImage *)captureScrollView:(UIScrollView *)scrollView
 2 {
 3     UIImage* image = nil;
 4     UIGraphicsBeginImageContext(scrollView.contentSize);
 5     {
 6         CGPoint savedContentOffset = scrollView.contentOffset;
 7         CGRect savedFrame = scrollView.frame;
 8         scrollView.contentOffset = CGPointZero;
 9         scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
10 
11         [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
12         image = UIGraphicsGetImageFromCurrentImageContext();
13 
14         scrollView.contentOffset = savedContentOffset;
15         scrollView.frame = savedFrame;
16     }
17     UIGraphicsEndImageContext();
18 
19     if (image != nil) {
20         return image;
21     }
22     return nil;
23 }

 

合并多张图片

 1 - (UIImage *)composeWithHeader:(UIImage *)header content:(UIImage *)content footer:(UIImage *)footer
 2 {
 3     CGSize size = CGSizeMake(content.size.width, header.size.height +content.size.height +footer.size.height);
 4     UIGraphicsBeginImageContext(size);
 5     [header drawInRect:CGRectMake(0,
 6                                   0,
 7                                   header.size.width,
 8                                   header.size.height)];
 9     [content drawInRect:CGRectMake(0,
10                                    header.size.height,
11                                    content.size.width,
12                                    content.size.height)];
13     [footer drawInRect:CGRectMake(0,
14                                   header.size.height+content.size.height,
15                                   footer.size.width,
16                                   footer.size.height)];
17 
18     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
19     UIGraphicsEndImageContext();
20     return image;
21 }

 

iOS 截图

标签:

原文地址:http://www.cnblogs.com/airy99/p/4529896.html

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