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;
    }

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

  • 相关阅读:
    JDBC
    Maven入门初级教程
    os.path路径拓展 python3
    requests实现文件下载, 期间显示文件信息&下载进度_python3
    yield浅析-Python3
    Scoop
    U盘启动盘制作工具(安装Linux)
    JavaScript摘要笔记
    Hexo+Github搭建博客&各种设置
    Linux下搭建svn服务端
  • 原文地址:https://www.cnblogs.com/wcLT/p/4211689.html
Copyright © 2011-2022 走看看