IOS 截屏||截图
来源:互联网 发布:流星网络电视tv版apk 编辑:程序博客网 时间:2024/05/01 20:02
#pragma mark - 截屏方法
/**
*@return UIImage
*/
+(UIImage *)ScreenShots
{
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions) {
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
}
else
{
UIGraphicsBeginImageContext(imageSize);
}
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *image = nil;
for (UIWindow * window in [[UIApplication sharedApplication] windows]) {
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {
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 ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
image = UIGraphicsGetImageFromCurrentImageContext();
} else {
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
}
CGContextRestoreGState(context);
}
}
UIGraphicsEndImageContext();
DLog(@"Suceeded!");
return image;
/**
*@return UIImage
*/
+(UIImage *)ScreenShots
{
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions) {
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
}
else
{
UIGraphicsBeginImageContext(imageSize);
}
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *image = nil;
for (UIWindow * window in [[UIApplication sharedApplication] windows]) {
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {
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 ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
image = UIGraphicsGetImageFromCurrentImageContext();
} else {
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
}
CGContextRestoreGState(context);
}
}
UIGraphicsEndImageContext();
DLog(@"Suceeded!");
return image;
}
//截图 ,将下面的window改成你要截图的对象即可
-(UIImage *)captureAndSaveView:(UIView *)view{
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 1.0); //NO,YES 控制是否透明
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = nil;
if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
image = UIGraphicsGetImageFromCurrentImageContext();
} else {
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
return image;
}
0 0
- IOS 截屏||截图
- ios 截屏,截图
- IOS屏幕截图---Opengl截屏
- ios截图
- iOS 截图
- IOS 截图
- iOS 截图
- ios 截图
- iOS截图
- iOS截图
- iOS截图
- iOS截图
- 截图 iOS
- iOS 截图
- IOS截图
- iOS截图
- ios-截图
- IOS 截图
- ajax的post
- OO多态性的一个体现
- Server.CreateObject("Excel.Application")的权限问题
- [POJ1681]画家问题
- WebDriver: Advanced Usage
- IOS 截屏||截图
- mongodb的group详细成功案例
- pig基础知识总结
- 为何OpenWrt能在这十年里脱颖而出?(转自雷锋网)
- C++的函数重载
- Java学习之Iterator(迭代器)的一般用法
- html Frame
- 服了,写了两篇博客也没人评论,本人打算写小说或者画漫画了,我的csdn是单机吗
- Hive运行架构及配置部署