How to take a screenshot when a webview finished rending

最后都变了- 提交于 2020-01-11 13:29:07

问题


I want to take a screenshot when a webview finished rending.The follow is my code:

-(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];
}
}

The normal image is that:

But my image is this:

Anyone tell me why and how could i improve this situation! Thank u!

来源:https://stackoverflow.com/questions/15051007/how-to-take-a-screenshot-when-a-webview-finished-rending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!