Generate document thumbnails

不打扰是莪最后的温柔 提交于 2019-12-09 13:56:18

问题


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.


回答1:


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..




回答2:


The better option of you can use a uiwebview in which you can just load the file giving the filepath. Then take the screen shot by using the code given above by Matic Oblak and you are done.



来源:https://stackoverflow.com/questions/11203088/generate-document-thumbnails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!