zoukankan      html  css  js  c++  java
  • iOS 手机截屏

    百度地图自带截图功能,可以截取路线列表,保存到本地。可是对比发现截下来的图片并不是app中看到的那样,截图中头部加入了搜索的起点和终点,每段路程的详细站点都已展开,而且图片会根据路线的长短自动判断图片的长度。于是猜想,百度地图的截图思路是:

    Step1:创建当前列表的头视图用于展示起始位置信息,获得视图1。

    Step2:重新创建新的站点列表视图,并将详细站点展开,获得视图2.

    Step3:创建容器视图(UIView或UIScrollView),将视图1与视图2放到容器视图中使用下面的方法截取视图创建图片。

    Step4:保存图片到本地相册,Over。

    截屏的方法如下:

    //获得屏幕图像
    - (UIImage *)imageFromView: (UIView *) theView
    {
        
        UIGraphicsBeginImageContext(theView.frame.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [theView.layer renderInContext:context];
        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        return theImage;
    }
    
    //获得某个范围内的屏幕图像
    - (UIImage *)imageFromView: (UIView *) theView   atFrame:(CGRect)r
    {
        UIGraphicsBeginImageContext(theView.frame.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSaveGState(context);
        UIRectClip(r);
        [theView.layer renderInContext:context];
        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        return  theImage;//[self getImageAreaFromImage:theImage atFrame:r];
    }
  • 相关阅读:
    eclipse常用快捷键
    Sql server 问题诊断
    Oracle 表格大小分析
    VM虚拟机增加磁盘空间
    Linux搭建Nexus+Maven私人仓库
    Linux 下安装Git 版本管理工具 使用记录
    Jenkins 环境打建设 Linux
    Oracle 数据库用户表大小分析
    Windgb 其他常用命令
    Windbg 查内存占用
  • 原文地址:https://www.cnblogs.com/PaulpauL/p/6515260.html
Copyright © 2011-2022 走看看