以编程方式截图在iPhone模拟器上工作正常,但不能在设备上

时间:2014-07-23 13:42:35

标签: ios iphone uiwebview screenshot fullscreen

我的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

iPhone Simulator ScreenShot

iDevice(iPhone)ScreenShot

iDevice (iPhone) ScreenShot

0 个答案:

没有答案