0

I'm trying to capture the contents of a WebView and saving it as an image. This is my code right now (cv is the web view):

[cv lockFocus];
        NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[cv bounds]];
        [cv unlockFocus];
        NSData *data = [rep TIFFRepresentation];
        [data writeToFile:[[save URL] path] atomically:NO];

All I get is a gray image with the correct size. What am I doing wrong?

Fatso
  • 1,278
  • 16
  • 46

1 Answers1

1

I don't think you are using correctly NSBitmaImageRep.

Have a look at this post for a couple of ways of doing what you are trying to. Possibly the only one that is working for a web view (which is quite a complex beast) is the screenshot+crop approach.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123