zoukankan      html  css  js  c++  java
  • IOS截屏

    最近,在找IOS截屏的方法。找到一个,现在记录下来。跟我想的差不多,还是,进入操作(初始化),操作(复制当前屏幕,保存),退出。最小的操作结构。

    1 . 先指定图像的大小

    UIGraphicsBeginImageContext(view.frame.size);

    2. 在指定的区域绘制图像

    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];

    3. 获取图像上下文

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    4. 关闭图像上下文

    UIGraphicsEndImageContext();

    没错!只需要4行代码就可以获取到指定View的图像截图。

    另外,常用的绘制图像还有另一个方法:

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    + (UIImage *)getImageViewWithView:(UIView *)view
    {
        UIGraphicsBeginImageContext(view.frame.size);
        [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        return image;
    }

     代码还是对现实世界的一个简单映射啊。只能做简单重复的操作。影响开发能力的还是人自己啊。

  • 相关阅读:
    JS监听组合按键
    XSS初体验
    debuggap,移动端调试新方式
    简析分页逻辑
    【译】Javascript中的数据类型
    【译】typeof null的前世今生
    一个跨域请求的XSS漏洞再续
    H5页面音频自动播放问题
    一个跨域请求的XSS续
    成功自我管理之压力管理
  • 原文地址:https://www.cnblogs.com/wcLT/p/4211689.html
Copyright © 2011-2022 走看看