我使用了一些 CIFilter
进行图像处理。我发现 UIImageView
在实时显示输出图像时速度太慢了。我按照 文档 中的说明构建了 GLKView
。现在表现非常出色,但当旋转图像时,图像呈黑色矩形。
如何将颜色设置为背景(在此示例中为绿色)或透明?
这是绘画代码片段。我对图像领域不熟悉。
private class ImageView: GLKView {
override init!(frame: CGRect, context: EAGLContext!) { // Called with `.OpenGLES3` context.
ciContext = CIContext(EAGLContext: context, options: [kCIContextWorkingColorSpace: NSNull()])
super.init(frame: frame, context: context)
}
private let ciContext: CIContext
private var image: CIImage? {
didSet {
setNeedsDisplay()
}
}
private override func drawRect(rect: CGRect) {
// Clear with `glClear`... Here is set color from `backgroundColor` (green) and cleared with it.
if image != nil {
ciContext.drawImage(image!, inRect: { /* returned computed rect */ }(), fromRect: image!.extent())
}
}
private override func layoutSubviews() {
super.layoutSubviews()
setNeedsDisplay()
}
}