【发布时间】:2013-08-19 09:48:49
【问题描述】:
我的应用程序中有一个UICollectionView,其单元格主要由UIImageViews 组成,其中包含已使用Core Image 处理以降低色彩饱和度的图像。滚动时的性能绝对可怕。当我分析它时,花费的大部分时间(80% 左右)不在我的代码中,甚至不在我的堆栈中。这一切似乎都在核心动画代码中。有人知道为什么会这样吗?
在我的 UICollectionViewCell 子类中,我有这样的东西:
UIImage *img = [self obtainImageForCell];
img = [img applySaturation:0.5];
self.imageView.image = img;
applySaturation 看起来像这样:
CIImage *image = [CIImage imageWithCGImage:self.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIColorControls"];
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:saturation] forKey:@"inputSaturation"];
return [UIImage imageWithCIImage:filter.outputImage];
我唯一的猜测是 Core Animation 不能很好地与 Core Image 配合使用。 Apple docs 这么说CIImage:
虽然 CIImage 对象具有与之关联的图像数据,但它不是图像。您可以将 CIImage 对象视为图像“配方”。 CIImage 对象拥有生成图像所需的所有信息,但 Core Image 在被告知之前不会真正渲染图像。这种“惰性评估”方法可以让 Core Image 尽可能高效地运行。
在制作动画时在最后一刻进行此评估可能会很棘手。
【问题讨论】:
-
您是否尝试过一次过滤并缓存结果?
-
我看到同样缓慢的滚动行为。
标签: ios performance uicollectionview core-image