+(UIImage*) imageByCaptureScreen {
if(UIGraphicsBeginImageContextWithOptions!=NULL)
{
UIGraphicsBeginImageContextWithOptions([UIScreenmainScreen].bounds.size,NO,0);
}
else
{
UIGraphicsBeginImageContext([UIScreenmainScreen].bounds.size);
}
CGContextRefcontext =UIGraphicsGetCurrentContext();
for(UIWindow*windowin[[UIApplicationsharedApplication]windows])
{
if(![windowrespondsToSelector:@selector(screen)] || [windowscreen] == [UIScreenmainScreen])
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, [windowcenter].x, [windowcenter].y);
CGContextConcatCTM(context, [windowtransform]);
if(IOS7_OR_LATER)
{
CGContextTranslateCTM(context,
-[windowbounds].size.width* [[windowlayer]anchorPoint].x,
-[windowbounds].size.height* [[windowlayer]anchorPoint].y);
}
else
{
CGContextTranslateCTM(context,
-[windowbounds].size.width* [[windowlayer]anchorPoint].x,
-[windowbounds].size.height* [[windowlayer]anchorPoint].y-20);
}
[[windowlayer]renderInContext:context];
CGContextRestoreGState(context);
}
}
UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnimage;
}
网友评论