Skip navigation.
 
mlRe: Capture WebView in a NSImage
FROM : cocoa
DATE : Wed Aug 16 12:02:43 2006

Indeed this does work - just last week I tracked down that method for 
doing it. Code pasted from my test app, but with irrelevant stuff 
removed:

<code>
-(void)webViewFinishedLoading:(id)sender {
    WebView *webView = [sender object];
    [progressBar incrementBy:1.0];

    [NSThread detachNewThreadSelector:@selector(processWebView:)
                              toTarget:self
                            withObject:webView];
}

-(void)processWebView:(WebView*)webView {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSBitmapImageRep *imageRep = [webView 
bitmapImageRepForCachingDisplayInRect:[webView frame]];
    [webView cacheDisplayInRect:[webView frame] toBitmapImageRep:imageRep];

    NSImageView *imageView = [[NSImageView alloc] initWithFrame:imageRect];
    [imageView setImageScaling:NSScaleProportionally];
    NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(1280, 1024)];
    [image addRepresentation:imageRep];

    // Set the image into the view
    [imageView setImage: image];

    [pool release];
}

</code>

Quoting Dan Bernstein <dan.<email_removed>>:

> I think sending -cacheDisplayInRect:toBitmapImageRep: to the WebView
> will do the trick. You can obtain an appropriate image rep using
> -bitmapImageRepForCachingDisplayInRect:
>
> On 7/26/06, Marcus S. Zarra <<email_removed>> wrote:

>> I am trying to capture a WebView in an NSImage but I am running into
>> issues.  Having searched Google, etc. I found a couple of exmples but
>> seem to be missing something as it  is not working.
>>
>> In my app, I init a WebView and give it a NSURLRequest and set a load
>> delegate.  In the delegate I have the following code:
>> <snip>

Related mailsAuthorDate
mlCapture WebView in a NSImage Marcus S. Zarra Jul 26, 20:26
mlRe: Capture WebView in a NSImage Dan Bernstein Aug 16, 10:33
mlRe: Capture WebView in a NSImage cocoa Aug 16, 12:02