Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating thumbnails of local webpages on iOS
    primarykey
    data
    text
    <p>I have a set of local HTML pages that I would like batch generate thumbnails for on the fly (I only want to show the thumbnails, not the full web pages). This is the way I'm accomplishing this:</p> <pre><code>NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:link]; NSURL* url = [NSURL fileURLWithPath:path]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 725, 1004)]; webView.delegate = cell; [webView loadRequest:request]; [self.view addSubview:webView]; // doesn't work without this line, but then the UIWebView is onscreen </code></pre> <p>Then in the delegate:</p> <pre><code>- (void)webViewDidFinishLoad:(UIWebView *)webView { [self performSelector: @selector(render:) withObject: webView afterDelay: 0.01f]; } - (void) render: (id) obj { UIWebView* webView = (UIWebView*) obj; CGSize thumbsize = CGSizeMake(96,72); UIGraphicsBeginImageContext(thumbsize); CGContextRef context = UIGraphicsGetCurrentContext(); CGFloat scalingFactor = thumbsize.width/webView.frame.size.width; CGContextScaleCTM(context, scalingFactor,scalingFactor); [webView.layer renderInContext: context]; UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.thumbnail.image = resultImage; } </code></pre> <p>Here are my questions:</p> <p>1) Is my general approach correct? Is this the most efficient way to batch process thumbnails of webpages on the fly?</p> <p>2) I want to be able to render the thumbnail from an offscreen UIWebView, but the webViewDidFinishLoad: doesn't get called unless I add the UIWebView to the view hierarchy. Is there a way I can avoid this?</p> <p>3) If I attempt to capture an image of the UIWebView in webViewDidFinishLoad:, I get a blank image. I have to put an artificial delay for the capture to work. Any way around this?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload