我想在 webview 完成渲染时截屏。以下是我的代码:
-(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];
}
}
正常的图像是这样的:
但我的形象是这样的:
任何人都告诉我为什么以及如何改善这种情况!感谢你!