Hi everybody i’m stuck with trying to convert my UIWebView, in which i’m currently displaying a ppt file, to a bitmap image.
I have this code:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 708)];
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
NSLog(@"Ouverture du contexte image");
UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
The webview is actually well displayed but I didn’t manage to create it’s render to an image,
If anybody knows where is the issue 😉
Thankss
There’s nothing wrong with your screenshot-taking code — you’re just using it prematurely.
[webView loadRequest:request];initiates an asynchronous client request. That means you’re taking a screenshot ofwebViewbefore it even loads its contents.Move your screenshot-taking code to
UIWebViewDelegate‘s methodwebViewDidFinishLoad:. Of course you’re going to have to assign adelegateto yourwebViewto achieve this.