天天看点

ios截屏使用的方法

- (UIImage*)getimage{//截屏使用的方法

CGSize imageSize = [[UIScreen mainScreen] bounds].size;

if (NULL != UIGraphicsBeginImageContextWithOptions) {

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

} else {

UIGraphicsBeginImageContext(imageSize);

}

CGContextRef context = UIGraphicsGetCurrentContext();

for (UIWindow *window in [[UIApplication siharedApplication] 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;

本文转自 卓行天下  51CTO博客,原文链接:http://blog.51cto.com/9951038/1616382,如需转载请自行联系原作者

继续阅读