objective-c - 如何从源服务器 URL 生成缩略图?

标签 objective-c swift image uitableview url

我想从原始源网址创建缩略图并在桌面 View 上显示模糊效果,例如 WhatsApp 我不想将两个单独的网址(低和高)上传到服务器,有人知道如何做到吗?帮助。

最佳答案

为此,您必须使用以下步骤: 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 中实现了

关于objective-c - 如何从源服务器 URL 生成缩略图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41458342/

相关文章:

ios - Mac Catalyst - 向 UITableView/UIScrollView 添加单击 + 拖动手势

ios - 如何从@implementation 外部调用方法?

ios - *** 集合 <__NSArrayM : 0x117d7320> was mutated while being enumerated. '

arrays - TableView 与所有习语

ios - 如何在Swift中显示数组列表对应的图像

swift - 如何使用多个子类作为函数参数

java - 如何减小图像尺寸?

ios - NSPredicate 与 NSNumbers 的 NSArray(核心数据)

PHP mySQL 将字符串转换为 png 仅适用于第一张图像

图像/表单到 Pascal/Delphi 代码转换器?