【问题标题】:Problems to create a Thumbnailimage from a WORD document in Objective c在 Objective c 中从 WORD 文档创建缩略图的问题
【发布时间】:2012-02-18 04:03:26
【问题描述】:

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

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

【问题讨论】:

    标签: objective-c ios thumbnails


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2012-01-29
        • 2011-11-28
        • 2010-11-03
        • 1970-01-01
        • 2011-02-25
        • 2011-02-08
        • 1970-01-01
        • 1970-01-01
        • 2011-04-13
        相关资源
        最近更新 更多