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];
    }
  • 相关阅读:
    jQuery对象和DOM对象
    虚拟主机的部署(Apache)
    事件流:事件冒泡和事件捕获
    ThinkPHP
    级联下拉列表
    今日份抽自己!!!
    c++中关于输入字符数组的一些问题
    今日新知(关于递归中变量的声明)
    格子游戏(并查集)
    1.3-14大象喝水
  • 原文地址:https://www.cnblogs.com/PaulpauL/p/6515260.html
Copyright © 2011-2022 走看看