Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何保存网页的缩略图?_Macos_Cocoa_Webview - Fatal编程技术网

Macos 如何保存网页的缩略图?

Macos 如何保存网页的缩略图?,macos,cocoa,webview,Macos,Cocoa,Webview,我想保存一个网页的缩略图。所以我创建了一个网络视图。代码是这样的 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { if (frame != [sender mainFrame]) { return; } [sender lockFocus]; NSData* data = [sender dataWithPDFInsideRect:[sender bounds]];

我想保存一个网页的缩略图。所以我创建了一个网络视图。代码是这样的

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
if (frame != [sender mainFrame]) {
    return;
}
    [sender lockFocus];
    NSData* data = [sender dataWithPDFInsideRect:[sender bounds]];
    [sender unlockFocus];
    NSImage *img = [[NSImage alloc] initWithData:data];
    NSData* imageData = [img TIFFRepresentation];
    NSArray* deskTopArrayPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
    NSString* deskTopPath = [deskTopArrayPaths objectAtIndex:0];
    NSString* pngPath = [NSString stringWithFormat:@"%@/SaveWebThumbnail.png",deskTopPath];
    [imageData writeToFile:pngPath atomically:NO];
}

但是保存的图像中有一些空白位置。我不知道为什么?我猜当webView:didFinishLoadForFrame:被调用时,webView还没有真正完成,不是吗?任何人知道解决方案,请告诉我,谢谢

webView:didFinishLoadForFrame:
在网页加载完成时被调用,这并不意味着它已完成渲染。。。也许您可以添加一些任意延迟,并希望在渲染完成之前完成渲染,或者在页面中插入JavaScript以在渲染完成时通知您…当网页渲染完成时?