繁体   English   中英

从Objective c中的WORD文档创建缩略图图像时遇到的问题

[英]Problems to create a Thumbnailimage from a WORD document in Objective c

我试图创建一个ThumbnailImage到Word文档。 我使用UIWebView加载文档,然后将其转换为图像。 ng 我已经看了一千遍了,文件路径是正确的,但是最终的图像是空白的。 有人可以查看我的代码,看看是否有问题? 提前非常感谢您。

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];

我很确定这是一个时间问题。 UIWebView具有自己的线程并异步加载文档,您需要等到加载完毕后才能使用renderInContext。

确定时间可能很棘手,无论是使用固定时间还是进行一些深子视图检查。

您可能想使用QuickLook而不是UIWebView来获得更多有关渲染的控制。

问题在于您正在触发请求,然后立即捕获图像。 loadRequest:是异步的。 它发送请求,并立即返回。 它不会等到文档加载后才返回。 因此,当您捕获图像时,设备仍在忙于加载文档。

您可以提供Web视图的委托,该委托在文档加载完成后会收到一条消息。 从该委托方法中捕获图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM