2017-01-04 33 views
0

我想從原始源URL創建縮略圖圖像,並顯示模糊效果,像WhatsApp我不想上傳兩個單獨的URL(低和高)到服務器,任何人都知道如何做到這一點?幫幫我。如何從源服務器url生成縮略圖圖片?

+0

你在原始源URL中有什麼?是視頻嗎? –

+0

@PiyushPatel,不,它是圖片網址。 – Bucket

+0

你的應用程序是基於快速還是Objective C? – Pushkraj

回答

0

對於您必須使用以下步驟: 1.下載圖像從URL中使用任何圖書館使用延遲加載機制 2.轉換圖像模糊之一,並顯示在UI 3.敲擊它後顯示與實際圖像緩存

您可以添加模糊效果與CIGaussianBlur效果

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; 
} 

只要按照上面的步驟來實現它的UIImageView。我在我的一個應用程序中完成了它,但是我在Objective C中實現了這個目標C