首页 > 代码库 > IOS 截屏
IOS 截屏
UIImage+Screenshot.h#import <UIKit/UIKit.h>@interface UIImage (Screenshot)+ (UIImage *)screenshot;@end#import "UIImage+Screenshot.h"@implementation UIImage (Screenshot)+ (UIImage *)screenshot{ CGSize imageSize = [[UIScreen mainScreen] bounds].size; if (NULL != UIGraphicsBeginImageContextWithOptions) { UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); } else { UIGraphicsBeginImageContext(imageSize); } 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
// 使用
UIImage *image = [UIImage screenshot];
IOS 截屏
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。