我想从原始源网址创建缩略图并在桌面 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/