Re: Capture WebView in a NSImage
Re: Capture WebView in a NSImage
- Subject: Re: Capture WebView in a NSImage
- From: email@hidden
- Date: Wed, 16 Aug 2006 11:02:43 +0100
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 <email@hidden>:
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@hidden> 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>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden