标签:
//
// STTools.h
// STWebViewController
//
// Created by linxiaolong on 15/5/11.
// Copyright (c) 2015年 linxiaolong. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface STTools : NSObject
+ (UIImage *)getScreenshot;
@end
//
// 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
标签:
原文地址:http://www.cnblogs.com/allen2015/p/4724963.html