iOS 截取当前屏幕
来源:互联网 发布:狂雷flv视频下载软件 编辑:程序博客网 时间:2024/05/29 23:46
截取当前屏幕内容 将以下代码粘贴复制 直接调用imageWithScreenshot方法/** * 截取当前屏幕 * * @return NSData * */- (NSData *)dataWithScreenshotInPNGFormat{ CGSize imageSize = CGSizeZero; UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (UIInterfaceOrientationIsPortrait(orientation)) imageSize = [UIScreen mainScreen].bounds.size; else imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width); UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); for (UIWindow *window in [[UIApplication sharedApplication] windows]) { CGContextSaveGState(context); CGContextTranslateCTM(context, window.center.x, window.center.y); CGContextConcatCTM(context, window.transform); CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y); if (orientation == UIInterfaceOrientationLandscapeLeft) { CGContextRotateCTM(context, M_PI_2); CGContextTranslateCTM(context, 0, -imageSize.width); } else if (orientation == UIInterfaceOrientationLandscapeRight) { CGContextRotateCTM(context, -M_PI_2); CGContextTranslateCTM(context, -imageSize.height, 0); } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { CGContextRotateCTM(context, M_PI); CGContextTranslateCTM(context, -imageSize.width, -imageSize.height); } if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES]; } else { [window.layer renderInContext:context]; } CGContextRestoreGState(context); } UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return UIImagePNGRepresentation(image);}/** * 返回截取到的图片 * * @return UIImage * */- (UIImage *)imageWithScreenshot{ NSData *imageData = [self dataWithScreenshotInPNGFormat]; return [UIImage imageWithData:imageData];}
0 0
- ios截取当前屏幕
- iOS 截取当前屏幕
- iOS 截取当前屏幕的方法
- 截取当前屏幕视图
- 截屏有截取当前屏幕
- IOS中截取当前屏幕,并保存图片
- IOS中截取当前屏幕,并保存图片
- IOS中截取当前屏幕,并保存图片
- iOS 截取屏幕当前显示的图片(可按范围截取)
- android截取系统当前屏幕
- 截取当前屏幕获得Bitmap
- iOS截取屏幕(屏幕截图)
- iOS 截图 截取屏幕
- iOS 截图 截取屏幕
- iOS 屏幕截取
- iOS 截取当前视图
- iOS中截取当前屏幕,并保存图片的代码例子
- iOS - 常用到的图片功能:截取当前屏幕/选择本地图片/图片压缩
- 文章标题 CSU 1845: Sensor network (暴力LCA+kruskal思想)
- javaIo 字符流
- Srping Mvc maven web
- react native 封装Touchable 组件
- Rabbit MQ 的配置与队列自动创建
- iOS 截取当前屏幕
- Linux下的JDK和tomcat的安装教程
- React 基础实例教程
- 划分方法
- PTA 数据结构与算法题目集(中文)5-11 关键活动 (30分)
- STL——Heap算法
- 1029. Median (25)
- Linux下的MySQL数据库的安装
- Redis 配置篇