码迷,mamicode.com
首页 > 移动开发 > 详细

iOS屏幕截图

时间:2015-08-12 18:30:02      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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

iOS屏幕截图

标签:

原文地址:http://www.cnblogs.com/allen2015/p/4724963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!