我正在尝试使用GLIKit View来修改图像.到目前为止,我所有的CIFilters工作都很好,除了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) } } }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。