2
私は選択UICollectionViewCell上で私のUIImageにそのフィルタを実装するいくつかのフィルタを持つアプリケーションを持っています。しかし、それは非常にゆっくりと凍って適用されます。画像上に画像フィルタを実装する速度をどのように高められますか?写真フィルタの実装速度をどのように高めることができますか?
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
}
これは私のフィルタコードです。そして、私は
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
}
バックグラウンドで実行させ、準備ができるまでローディングバーを表示することができますか? – Eric
イメージを縮小してみましたか?あなたが最適化するために必要な最も集中的なコードを見つけるために、Time Profilerを実行します。 –