-(void)fullScreenshots{

UIWindow *screenWindow = [[UIApplicationsharedApplication] keyWindow];

UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window

[screenWindow.layerrenderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

//    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

float originX =_sampleView.frame.origin.x;

float originy =_sampleView.frame.origin.y;

float width =_sampleView.frame.size.width;

float height =_sampleView.frame.size.height;

//你需要的区域起点,宽,高;

CGRect rect1 =CGRectMake(originX , originy , width , height);

UIImage * imgeee = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([viewImageCGImage], rect1)];

UIImageView *snapImg = [[UIImageViewalloc] initWithFrame:CGRectMake(0,200,170,170)];

snapImg.backgroundColor = [UIColorredColor];

snapImg.image = imgeee;

[self.viewaddSubview:snapImg];

}

或者:

- (void)snapAction:(UIButton *)btn {

UIImage *image = [self snapshot:_sampleView];

UIImageView *snapImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,200, 170, 170)];

snapImg.layer.borderWidth = 1;

snapImg.image = image;

[self.view addSubview:snapImg];

}

- (UIImage *)snapshot:(UIView *)view {

UIGraphicsBeginImageContextWithOptions(view.bounds.size,YES,0);

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

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

感谢分享

iOS 获取屏幕某个区域的截图-b的更多相关文章

  1. ios 获取屏幕的属性和宽度

    app尺寸,去掉状态栏 CGRect r = [ UIScreen mainScreen ].applicationFrame; r=0,20,320,460 屏幕尺寸 CGRect rx = [ U ...

  2. iOS获取屏幕亮度及设置

    平常很少有功能点需要调整屏幕亮度,但是也会有一些特殊场景,类似支付宝微信的二维码提供扫描时会使屏幕程序高亮状态,查了下资料做了一下简单记录: 获取当前屏幕的亮度 CGFloat value = [UI ...

  3. IOS 获取屏幕尺寸

    CGRect frame = [[UIScreen mainScreen] bounds];    NSLog(@"frame :%@",frame); 这样输入是null NSL ...

  4. ios 获取屏幕的属性

    屏幕尺寸     CGRect screen = [UIscreen mainScreen].bounds 状态栏尺寸  CGRect rect = [[UIApplication sharedApp ...

  5. 获取屏幕宽高度与可视区域宽高度(availWidth、clientWidth、width、innerWidth)

    经常会遇到需要获取屏幕宽度.高度,可视区域宽度.高度等问题,也就常跟这几个打交道,一不小心,还真爱弄混淆了. 先来列举下这几个吧: screen.availHeight.screen.availWid ...

  6. IOS开发之——获取屏幕的尺寸及各模拟器代表的型号

    获取屏幕尺寸 [[[UIScreen mainScreen] currentMode].size.width]; [[[UIScreen mainScreen] currentMode].size.h ...

  7. HTML 获取屏幕、浏览器、页面的高度宽度

    本篇主要介绍Web环境中屏幕.浏览器及页面的高度.宽度信息. 目录 1. 介绍:介绍页面的容器(屏幕.浏览器及页面).物理尺寸与分辨率.展示等内容. 2. 屏幕信息:介绍屏幕尺寸信息:如:屏幕.软件可 ...

  8. iOS获取iPhone系统等信息和服务器返回空的异常处理

    前言: 在项目中经常会遇到需要获取系统的信息来处理一些特殊的需求和服务端返回为空的处理,写在这里只是笔记一下. 获取设备的信息 NSLog(@"globallyUniqueString=%@ ...

  9. 图解js中常用的判断浏览器窗体、用户屏幕可视区域大小位置的方法

    有时我们需要获得浏览器窗口或屏幕的大小.窗口下拉框下拉的距离等数据,对应这些需求,js中提供了不少解决方法,只是数量稍多容易混淆它们各自的意义,下面咱们用图例来解释下12个常见对象属性的作用. 其中有 ...

随机推荐

  1. mysql插入中文乱码问题

    1.show variables like 'character%' 2.修改 MySql安装目录下面的my.ini(MySQL Server Instance Configuration 文件). ...

  2. JAVA 垃圾收集监控

    我们可以使用Java命令行和UI工具来监控应用程序的垃圾收集活动.下面的例子中,我使用Java SE Downloads 中一个演示程序. 如果你想使用同样的程序,前往 Java SE Downloa ...

  3. 二叉树遍历-JAVA实现

    二叉树遍历分为前序.中序.后序递归和非递归遍历.还有层序遍历. //二叉树节点 public class BinaryTreeNode { private int data; private Bina ...

  4. FIS3中使用less

    安装插件: npm install -g fis-parser-less npm install -g fis3-postpackager-loader 配置:fis-conf.js 使用fis-pa ...

  5. Computer Vision Tutorials from Conferences (2) -- ECCV

    ECCV 2012 (http://eccv2012.unifi.it/program/tutorials/) Vision Applications on Mobile using OpenCVGa ...

  6. OpenCV Harris 角点检测子

    Harris 角点检测子 目标 本教程中我们将涉及: 有哪些特征?它们有什么用? 使用函数 cornerHarris 通过 Harris-Stephens方法检测角点. 理论 有哪些特征? 在计算机视 ...

  7. 权限项目总结(四) shiro 授权

    概述 Authorization(授权):不难理解,授权就是用来控制当前訪问用户在訪问系统资源权限. 这个词也做证书的解释,从证书这个角度来讲,推断是否拥有对资源訪问的权限时.当前用户须要提供证书. ...

  8. 数学图形(1.18)Poinsot's spiral螺线

    它是一种螺线,其特点是细分时无限递归. 相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 vertices = t = *PI ...

  9. 改善你的jQuery的25个步骤

    1. 从Google Code加载jQueryGoogle Code上已经托管了多种JavaScript类库,从Google Code上加载jQuery比直接从你的服务器加载更有优势.它节省了你服务器 ...

  10. qt study 泛型和容器

    所谓泛型(generic) 能够像操作基本类型一样轻松操作对象的类和函数. qt容器类就是泛型类,基于模板的泛型类. 重载运算符overloaed operator, 托管容器 managed con ...