Re: Capture WebView in a NSImage
Re: Capture WebView in a NSImage
- Subject: Re: Capture WebView in a NSImage
- From: "Dan Bernstein" <email@hidden>
- Date: Wed, 16 Aug 2006 10:33:58 +0200
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:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
NSRect workingRect = NSMakeRect(0, 0, 400, 400);
NSWindow *tempWindow = [[NSWindow alloc]
initWithContentRect:workingRect styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:NO];
[tempWindow setContentView:sender];
NSImage *image = [[NSImage alloc] initWithSize:workingRect.size];
[image lockFocus];
[sender drawRect:workingRect];
[image unlockFocus];
NSWindow *imageWindow = [[NSWindow alloc]
initWithContentRect:workingRect styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:NO];
NSImageView *imageView = [[NSImageView alloc]
initWithFrame:[imageWindow frame]];
[imageView setImage:image];
[imageWindow setContentView:imageView];
[imageWindow orderFront:nil];
}
If I call -orderFront: on the tempWindow I see the webpage as one
would expect. However the image is not populated with the webview.
I have also tried generating the image as such:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
NSRect workingRect = NSMakeRect(0, 0, 800, 800);
NSWindow *tempWindow = [[NSWindow alloc]
initWithContentRect:workingRect styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:NO];
[[tempWindow contentView] addSubview:sender];
[sender lockFocus];
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc]
initWithFocusedViewRect:workingRect] autorelease];
NSImage *image = [[[NSImage alloc] init] autorelease];
[image addRepresentation:rep];
[sender unlockFocus];
NSWindow *imageWindow = [[NSWindow alloc]
initWithContentRect:workingRect styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:NO];
NSImageView *imageView = [[NSImageView alloc]
initWithFrame:[imageWindow frame]];
[imageView setImage:image];
[imageWindow setContentView:imageView];
[imageWindow orderFront:nil];
}
With the same result. What am I missing?
Thanks for any help.
Marcus S. Zarra
Zarra Studios LLC
www.zarrastudios.com
Simply Elegant Software for OS X
_______________________________________________
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
_______________________________________________
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