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

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

  • 相关阅读:
    JavaScript基础学习篇
    js,html,css注释大集合
    JS中的专业术语
    BFC给我的帮助以及对hasLayout的认识
    框架
    PHP echo和print语句
    PHP变量
    PHP语法
    PHP入门
    SQLite学习网址
  • 原文地址:https://www.cnblogs.com/wcLT/p/4211689.html
Copyright © 2011-2022 走看看