Как сделать снимок экрана, когда веб-просмотр закончил рендерить
Я хочу сделать снимок экрана, когда веб-просмотр закончил рендерить. Ниже приведен мой код:
-(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];
}
}
Нормальное изображение таково:
Но мое изображение таково:
Кто-нибудь сказать мне, почему и как я могу улучшить эту ситуацию! Спасибо!