• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Capture WebView in a NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Capture WebView in a NSImage (From: "Dan Bernstein" <email@hidden>)

  • Prev by Date: Re: NSDirectoryEnumerator Question
  • Next by Date: GarageBandView? iMovieView? NSTimeLineView?
  • Previous by thread: Re: Capture WebView in a NSImage
  • Next by thread: GarageBandView? iMovieView? NSTimeLineView?
  • Index(es):
    • Date
    • Thread