如何采取截图的时候网页视图完成撕心裂肺(How to take a screenshot when

2019-08-17 03:35发布

我想采取截图的时候网页视图完成rending.The遵循的是我的代码:

-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
    if (frame != [sender mainFrame]) {
    return;
}
    NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[sender bounds]] autorelease];

if (rep){
    NSImage *img = [[NSImage alloc] initWithData:[rep TIFFRepresentation]];
    NSData* imgData = [img TIFFRepresentation];

    NSArray* deskTopArrayPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
    NSString* deskTopPath = [deskTopArrayPaths objectAtIndex:0];
    NSString* pngPath = [NSString stringWithFormat:@"%@/SaveWebPage.png",deskTopPath];
    [[NSFileManager defaultManager] createFileAtPath:pngPath contents:imgData attributes:nil];
}
}

正常的图像是:

但是,我的形象是这样的:

谁能告诉我为什么,我怎么能改善这种情况! 感谢你!

文章来源: How to take a screenshot when a webview finished rending