-(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. JAVA容器-模拟LinkedList实现(双链表)

    概述 LinkedList实质上就是双向链表的拓展的实现,我们将关注一下问题.LinkedList 1.双向链表怎么来实现插入.删除.查询? 2.利用二分法提高查询效率. 3.不同步,线程不安全,需要 ...

  2. apache&mod_wsgi&django部署多个项目

    今天做好了第二个django项目,但在部署时出了一点小问题,在此记录一下. 1.mod_wsgi 3.4已经支持了部署多个项目,只需在httpd.conf中进行如下配置: WSGIScriptAlia ...

  3. Switch debouncer uses only one gate

    The circuit in Figure 1 produces a single debounced pulse each time you press S1. Moreover, the circ ...

  4. 插值技术之Bezier插值(1) -- Bezier Curve

    作者:i_dovelemon 来源:CSDN 日期:2015 / 7 / 11 主题:Interpolate,Bezier Curve 引言 在游戏开发中.诸如动画系统.路径计算等等操作,都会遇到对数 ...

  5. Eclipse:The superclass javax.servlet.http.HttpServlet was not found on the Java Build Path

    我们在用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not found on t ...

  6. 阻止picker.js插件弹出键盘

    <input id="focus" type="text" value="" placeholder="手机号" ...

  7. 虚拟机安装Linux过程和踩坑

    由于想学习node,服务器端大都使用Linux系统,所以就想着在笔记本上弄个虚拟机,装上Linux,使用xshell在window上操作也方便,也借此来熟悉一下Linux,接下来就解释下安装的步骤和遇 ...

  8. EntityFramework:我想我需要和 Session.Save 语义一样的方法

    背景 EntityFramework 中 DbSet.Add 方法不会导致立即执行 insert 语句,这在长事务中非常有用,不过多数用例都是短事务的,为何我需要一个立即执行 insert 语句的方法 ...

  9. Unity3d 换装 之 模型动画分离

    在手游中换装成了越来越不可缺的一个功能,毫无疑问各式各样的时装为游戏增添了不同的色彩. 对于2D手游,或许是更换对应的序列帧,也或许是如同3D手游一般,更换模型动画. 对于游戏中的人物,一般分为头.上 ...

  10. Latex中为作者添加多个单位属性(IEEE模板)

    \author{ \IEEEauthorblockN{name1 name1\IEEEauthorrefmark{1}\IEEEauthorrefmark{2},  name2 name2\IEEEa ...