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 cant 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!
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 cant 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!