【问题标题】:How to generate thumbnail image from source server url?如何从源服务器 url 生成缩略图?
【发布时间】:2017-05-18 10:05:52
【问题描述】:

我想从原始源 url 创建缩略图图像并在 WhatsApp 之类的 tableview 上显示模糊效果我不想将两个单独的 url(低和高)上传到服务器,有人知道怎么做吗?帮助。

【问题讨论】:

  • 原始源网址中有什么?是视频吗?
  • @PiyushPatel,不,是图片网址。
  • 你的应用是基于 swift 还是 Objective c?
  • 让您的 Web 开发人员处理这个...假设路径是 /uploads/high/1.png。开发人员也会将图像保存在 /low/ 文件夹中。你要做的是将 /high/ 替换为 /low/
  • @Pushkraj 它是 swift 语言。

标签: objective-c swift image uitableview url


【解决方案1】:

为此,您必须使用以下步骤: 1. 使用任何库使用延迟加载机制从 URL 下载图像 2. 将图像转换为模糊图像并在 UI 上显示 3.点击后显示缓存中的实际图像

您可以使用CIGaussianBlur 效果为 UIImageView 添加模糊效果

func getBlurImageFrom(image image: UIImage) -> UIImage {
    let radius: CGFloat = 20;
    let context = CIContext(options: nil);
    let inputImage = CIImage(CGImage: image.CGImage!);
    let filter = CIFilter(name: "CIGaussianBlur");
    filter?.setValue(inputImage, forKey: kCIInputImageKey);
    filter?.setValue("\(radius)", forKey:kCIInputRadiusKey);
    let result = filter?.valueForKey(kCIOutputImageKey) as! CIImage;
    let rect = CGRectMake(radius * 2, radius * 2, image.size.width - radius * 4, image.size.height - radius * 4)
    let cgImage = context.createCGImage(result, fromRect: rect);
    let returnImage = UIImage(CGImage: cgImage);

    return returnImage;
} 

只需按照上述步骤即可实现。我在我的一个应用程序中做到了,但我在 Objective C 中实现了

【讨论】:

    猜你喜欢
    • 2012-12-08
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    相关资源
    最近更新 更多