Swift2 Swift-GLKit查看过滤器图像
我试图使用Swift2 Swift-GLKit查看过滤器图像,swift2,glkit,cifilter,Swift2,Glkit,Cifilter,我试图使用GLIKit视图来修改图像。到目前为止,我使用的类在所有cifilter中都运行良好,除了CILineOverlay它呈现黑色视图。如果我使用其他效果,效果会很好 为什么CILineOverlay不显示 class ImageView: GLKView { let clampFilter = CIFilter(name: "CIAffineClamp")! let blurFilter = CIFilter(name: "CILineOverlay")! let
GLIKit视图
来修改图像。到目前为止,我使用的类在所有cifilter中都运行良好,除了CILineOverlay
它呈现黑色视图。如果我使用其他效果,效果会很好
为什么CILineOverlay
不显示
class ImageView: GLKView {
let clampFilter = CIFilter(name: "CIAffineClamp")!
let blurFilter = CIFilter(name: "CILineOverlay")!
let ciContext:CIContext
override init(frame: CGRect) {
let glContext = EAGLContext(API: .OpenGLES2)
ciContext = CIContext(
EAGLContext: glContext,
options: [
kCIContextWorkingColorSpace: NSNull()
]
)
super.init(frame: frame, context: glContext)
enableSetNeedsDisplay = true
}
required init(coder aDecoder: NSCoder) {
let glContext = EAGLContext(API: .OpenGLES2)
ciContext = CIContext(
EAGLContext: glContext,
options: [
kCIContextWorkingColorSpace: NSNull()
]
)
super.init(coder: aDecoder)!
context = glContext
enableSetNeedsDisplay = true
}
@IBInspectable var inputImage: UIImage? {
didSet {
inputCIImage = inputImage.map { CIImage(image: $0)! }
}
}
@IBInspectable var blurRadius: Float = 0 {
didSet {
//blurFilter.setValue(blurRadius, forKey: "inputIntensity")
setNeedsDisplay()
}
}
var inputCIImage: CIImage? {
didSet { setNeedsDisplay() }
}
override func drawRect(rect: CGRect) {
if let inputCIImage = inputCIImage {
clampFilter.setValue(inputCIImage, forKey: kCIInputImageKey)
blurFilter.setValue(clampFilter.outputImage!, forKey: kCIInputImageKey)
let rect = CGRect(x: 0, y: 0, width: drawableWidth, height: drawableHeight)
ciContext.drawImage(blurFilter.outputImage!, inRect: rect, fromRect: inputCIImage.extent)
}
}
}
苹果文档声明“图像中没有轮廓的部分是透明的。”-这意味着你正在黑色背景上画黑线。您可以简单地在白色背景上合成过滤器的输出,以使线条显示:
let background = CIImage(color: CIColor(color: UIColor.whiteColor()))
.imageByCroppingToRect(inputCIImage.extent)
let finalImage = filter.outputImage!
.imageByCompositingOverImage(background)
如此明显,但同时并非如此。非常感谢!