我想保存网页的缩略图。所以我创建了一个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还没有真正完成,不是吗?任何人都知道这个问题,请告诉我谢谢!