首页 > 移动平台 > 详细

iOS屏幕截图

时间:2015-08-12 18:28:01      阅读:153      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!