forked from wfxiaolong/STWebViewController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTTools.m
More file actions
38 lines (31 loc) · 1.27 KB
/
STTools.m
File metadata and controls
38 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// STTools.m
// STWebViewController
//
// Created by linxiaolong on 15/5/11.
// Copyright (c) 2015年 linxiaolong. All rights reserved.
//
#import "STTools.h"
@implementation STTools
#pragma -mark get screen shot
+ (UIImage *)getScreenshot {
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
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);
[[window layer] renderInContext:context];
CGContextRestoreGState(context);
}
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end