简体   繁体   English

生成文档缩略图

[英]Generate document thumbnails

I am trying to display a grid of documents (saved in the documents directory) but I don't know how to generate the thumbnails for the documents. 我正在尝试显示文档网格(保存在documents目录中),但是我不知道如何为文档生成缩略图。 The documents can be anything that a QLPreviewController can display. 这些文档可以是QLPreviewController可以显示的任何内容。 PDF's and Images are fine to do but other things like .doc's I don't know about. PDF和Images可以很好地完成,但是其他诸如.doc之类的东西我都不知道。 Any guidance would help. 任何指导都会有所帮助。

Since you have an UIView that can display any of this documents you could just take a shortcut: 由于您拥有一个可以显示其中任何文档的UIView,因此可以采用一种快捷方式:

-Create an instance of your preview controller with displayed document -使用显示的文档创建预览控制器的实例

-Do not add this view/controller to anything -不要将此视图/控制器添加到任何东西

-Create image from its layer -从其图层创建图像

This might help: 这可能会有所帮助:

+ (UIImage *)imageFromView:(UIView *)view {
    CALayer *layer = view.layer;
    UIGraphicsBeginImageContext([layer frame].size);
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();    
    return outputImage;
}

Play around a bit with layers and initialization as I didn't test the code.. 由于我没有测试代码,因此需要进行一些分层和初始化工作。

The better option of you can use a uiwebview in which you can just load the file giving the filepath. 更好的选择是使用uiwebview,您可以在其中加载文件并提供文件路径。 Then take the screen shot by using the code given above by Matic Oblak and you are done. 然后使用Matic Oblak上面给出的代码拍摄屏幕快照,您就完成了。

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

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