Quote:
Originally Posted by pepone63
I'm trying to create a ThumbnailImage to Word document. I use a UIWebView to load the document and then transform it into an image. Png. I've watched a thousand times and the file path is correct, but the final image is blank. Someone can look at my code to see if there is something wrong?. Thank you very much in advance.
Code:
UIWebView *myWebView22 = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
path44 = [caminoINICIAL stringByAppendingPathComponent:@"documentoInicial.doc"];
NSURL *fileURL22 = [[NSURL alloc] initFileURLWithPath:path44];
NSURLRequest *req22 = [NSURLRequest requestWithURL:fileURL22];
[myWebView22 setScalesPageToFit:YES];
[myWebView22 loadRequest:req22];
UIGraphicsBeginImageContext(myWebView22.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, 0, 0);
[myWebView22.layer renderInContext:c];
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
pngPath = [caminoINICIAL stringByAppendingPathComponent:[NSString stringWithFormat:@"imagenFinal.png"]];
[UIImagePNGRepresentation(viewImage) writeToFile:pngPath atomically:YES];
|
Web views are complex beasts, with lots of internal structure. It may be that you can't simply capture the view's layer as you are doing and get it to work.
You might try enclosing the web view in a container view exactly the same size, and capturing the container view's layer to a bitmap. The containing view should flatten the web view's private view hierarchy and let you capture the image you are after.
I'm guessing, though, since I've never tried it.