Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

binjaja

macrumors newbie
Original poster
Nov 13, 2008
10
0
I want to snapshot a UIWebView that has NEVER been visible in a view and the renderInContext doesn't seem to work.. I use the following code:

UIGraphicsBeginImageContext(testWebView.bounds.siz e);
[testWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
testImageView.image = viewImage;



However, the above code ONLY works if I make the testWebView visible in a window. To make it work I need to add testWebView as a subview of a visible view, otherwise I can’t seem to snapshot it into an image...the image just comes back as a dark gray box. Can you graphics-smarties help please!

(What I'm doing is prefetching 30 URLs and snapshotting their images to quickly show the user. Later the user can select an image and the UIWebview will (hopefully) load it from the cache...althought thats a whole other problem..UIWebView doesn't seem to cache with NSURLRequestReturnCacheDataElseLoad set!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.