天天看點

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,如需轉載請自行聯系原作者

繼續閱讀