Image from WebView is sometimes blank
Image from WebView is sometimes blank
- Subject: Image from WebView is sometimes blank
- From: Duncan Oliver <email@hidden>
- Date: Tue, 11 May 2010 16:33:07 -0500
I have a WebView that I use to capture a thumbnail of a loaded webpage
using cacheDisplayInRect:. The WebView object is created
programmatically and not attached to a window. About half the time,
the image it grabs is blank. I can't seem to figure out if I'm trying
to grab it too soon or what. Would love to know how to get a completed
image all the time. Thanks in advance.
Here's the code:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
if ([frame isEqualTo:[sender mainFrame]])
{
if ([sender saveThumbnail] == YES)
{
NSView *mainFrameView = sender.mainFrame.frameView;
NSBitmapImageRep *thumbnailImageRep = [mainFrameView
bitmapImageRepForCachingDisplayInRect:[mainFrameView frame]];
[sender cacheDisplayInRect:[mainFrameView frame]
toBitmapImageRep:thumbnailImageRep];
NSData *thumbnailPNGData = [thumbnailImageRep
representationUsingType:NSPNGFileType
properties:nil];
[[sender point] setValue:thumbnailPNGData
forKey:@"thumbnail"];
…
}
}
}
}
---
Duncan Oliver
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden