• iOS 截图


    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 }
  • 相关阅读:
    《构建之法》阅读报告
    教务管理系统类图及数据库E/R图
    设计模式:抽象工厂
    结对项目:四则运算程序测试
    Leetcode笔记之57和为s的连续正数序列
    Leetcode笔记之1103分糖果 II
    Leetcode笔记之199二叉树的右视图
    每日Scrum(9)
    每日Scrum(7)
    每日Scrum(6)
  • 原文地址:https://www.cnblogs.com/airy99/p/4529896.html
Copyright © 2020-2023  润新知