手机截屏
来源:互联网 发布:gameengine 源码 编辑:程序博客网 时间:2024/06/11 19:48
//添加截屏监听
[[NSNotificationCenterdefaultCenter]addObserverForName:UIApplicationUserDidTakeScreenshotNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
// executes after screenshot
NSLog(@"截屏");
[self imageWithScreenshot];
}];
/**
* 截取当前屏幕
*
*/
- (UIImage *)imageWithScreenshot
{
CGSize imageSize =CGSizeZero;
UIInterfaceOrientation orientation = [UIApplicationsharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation))
imageSize = [UIScreenmainScreen].bounds.size;
else
imageSize = CGSizeMake([UIScreenmainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
UIGraphicsBeginImageContextWithOptions(imageSize,NO,0);
CGContextRef context =UIGraphicsGetCurrentContext();
for (UIWindow *windowin [[UIApplicationsharedApplication]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);
}
elseif (orientation ==UIInterfaceOrientationLandscapeRight)
{
CGContextRotateCTM(context, -M_PI_2);
CGContextTranslateCTM(context, -imageSize.height,0);
} elseif (orientation ==UIInterfaceOrientationPortraitUpsideDown) {
CGContextRotateCTM(context,M_PI);
CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
}
if ([windowrespondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
{
[window drawViewHierarchyInRect:window.boundsafterScreenUpdates:YES];
}
else
{
[window.layerrenderInContext:context];
}
CGContextRestoreGState(context);
}
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnimage;
}
- Android手机截屏
- 手机截屏
- htc手机截屏
- android手机截屏
- Android 手机截屏
- 手机截屏
- Android 手机截屏
- android --手机截屏
- 手机如何截屏?
- Android 手机截屏
- 手机截屏
- 手机截屏
- Android下手机截屏
- 监听手机截屏事件
- android 禁止手机截屏
- android--代码实现手机截屏
- java实现手机截屏工具
- Android手机各种截屏方法
- VC2010调用DLL及调试DLL
- ExpandListView使用详解,一篇足够
- Oracle树查询(查询所有子节点,父节点等等)
- 安装 Rancher OS + gitlab 容器 趟坑记录
- esri-leaflet入门教程(1)-esri leaflet介绍
- 手机截屏
- c++ vector用法
- 单个爬虫文件使用scrapy保存为csv格式
- JS Form表单提交文件后,自定义跳转或提示
- 人脸识别--SphereFace: Deep Hypersphere Embedding for Face Recognition
- java 设计模式
- 总结
- HTML段落
- web.xml详解,