我的Snap shot代码在iPhone模拟器中工作正常,但如果我使用的是该代码,它会给我空白图片,
此代码用于拍摄uiwebview的快照浏览YouTube视频
//code for take snap shot
CGSize imageSize = CGSizeZero;
imageSize = [UIScreen mainScreen].bounds.size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO,0);
CGContextRef context = UIGraphicsGetCurrentContext();
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
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);
if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
{
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
}
else
{
[window.layer renderInContext:context];
}
CGContextRestoreGState(context);
}
// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
现在为iPhone模拟器和iPhone设备输出
iPhone模拟器ScreenShot
iDevice(iPhone)ScreenShot