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
duncan.oli...@gmail.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to