【问题标题】:Thumbnail from NSURL来自 NSURL 的缩略图
【发布时间】:2011-04-26 15:27:59
【问题描述】:

我正在加载从 Web 下载到 UIWebView 中的文件(HTML 文件)。

有没有办法从 Documents 文件夹中的 HTML 文件创建 UIImage?

目标是自动生成缩略图而不需要手动创建它们...

更新
我的思路是按照以下方式做一些事情:

NSString * s =  [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
UIImage *image = [[UIImage alloc] initWithData:
                                  [NSData dataWithContentsOfURL:url]];

在这种情况下当然不行!

谢谢!

S.

【问题讨论】:

    标签: objective-c ios


    【解决方案1】:

    我找到了这个解决方案here

    UIGraphicsBeginImageContext(yourWebView.bounds.size);
    [yourWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *resultImageView = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    resultImageView 将是一个包含yourWebView 渲染的图像。

    如果您想从那里将​​其缩小到缩略图大小,我喜欢Trevor's UIImage category

    【讨论】:

    • 我实际上是想在呈现 HTML 文件之前批量创建缩略图...
    • 将 HTML 呈现到布局中的东西是 UIWebView。是否首先在屏幕上呈现该视图完全是另一回事——如果你愿意,你可以在屏幕外的 CGRect 中完成这一切。但我不知道使用 UIWebView 进行布局的方法。
    猜你喜欢
    • 2012-11-07
    • 2013-02-21
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 2017-10-21
    相关资源
    最近更新 更多