生成文档缩略图 [英] Generate document thumbnails
问题描述
我正在尝试显示文档网格(保存在文档目录中)但我不知道如何生成文档的缩略图。文档可以是 QLPreviewController
可以显示的任何内容。 PDF和图像很好,但其他的东西,如.doc我不知道。任何指导都会有所帮助。
由于你有一个可以显示任何这些文件的UIView,你只需要一个快捷方式: / p>
- 用显示的文档创建预览控制器的实例
- 不要将此视图/控制器添加到任何内容
从图层创建图片
这可能有所帮助:
+(UIImage *)imageFromView:(UIView *)view {
CALayer * layer = view.layer;
UIGraphicsBeginImageContext([layer frame] .size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
返回outputImage;
}
使用图层和初始化稍微玩一下,因为我没有测试代码..
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. The documents can be anything that a QLPreviewController
can display. PDF's and Images are fine to do but other things like .doc's I don't know about. Any guidance would help.
Since you have an UIView that can display any of this documents you could just take a shortcut:
-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..
这篇关于生成文档缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!