I have an app where on select UICollectionViewCell with some filter it implements that filter to my UIImage. But it applies this so slowly and with freezes. How can I rise the speed of implementing image filters on my images?
func applyFilter(image: UIImage) -> UIImage {
var filter = CIFilter(name: "CIColorCube")
filter!.setValue(colorCubeData, forKey: "inputCubeData")
filter!.setValue(kDimension, forKey: "inputCubeDimension")
let sourceImage = CIImage(image: image)
filter.setValue(sourceImage, forKey: kCIInputImageKey)
let context = CIContext(options: nil)
let outputCGImage = context.createCGImage(filter.outputImage!, fromRect: filter.outputImage!.extent)
let newImage = UIImage(CGImage: outputCGImage, scale: 1.0, orientation: self.imageView.image!.imageOrientation)
return newImage
}
that's my filter code. And I call that in
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("filterCell", forIndexPath: indexPath) as! FiltersCollectionViewCell
let op1 = NSBlockOperation { () -> Void in
NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
cell.imageView.image = self.applyFilter(image: self.croppedImage!)
})
}
self.queue!.addOperation(op1);
return cell
}
Aucun commentaire:
Enregistrer un commentaire