0

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

- (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 还没有真正完成,不是吗?哪位知道解决方法,请告诉我,谢谢!

4

0 回答 0