Search code examples
cocoawebviewnsdatansimage

How to get image data from a WebView into an NSData object?


I have a Cocoa app that embeds a WebView. The WebView loads html elements including images. I have the textual links for the images (e.g. "http://www.domain.com/path/image.jpg"), but what I want is the image data itself so I can put it in an NSData object and ship it off to Growl. The WebView must have this data since it has downloaded and rendered the image. How can I get at it?


Solution

  • Try this:

    1. Get the web view's main frame.
    2. Get the frame's data source.
    3. Ask the data source for the downloaded resource for the image URL.
    4. Get the resource's data.