我试图在Swift中编写自己的CIFilter。我遇到的问题是关于班级真正的牛肉,这是outputImage
方法:
class CustomFilter : CIFilter {
var kernel: CIKernel
var inputImage: CIImage
var color: CIColor
var threshold: NSNumber
// ... stuff omitted ...
func outputImage() -> CIImage {
let zero = NSNumber(double: 0 as Double)
let width = NSNumber(double: inputImage.extent().size.width.native as Double)
let height = NSNumber(double: inputImage.extent().size.height.native as Double)
let src = CISampler(image: inputImage)
let arguments = [src, color, threshold] as [AnyObject]
let extent = [zero, zero, width, height]
return self.apply(
kernel,
arguments: arguments,
options: (kCIApplyOptionExtent: extent)
)
}
}
有关方法最后一行的编译器错误消息如下:
无法转换表达式'(@ lvalue CIKernel,参数: [AnyObject],options:(kCIApplyOptionExtent:[NSNumber]))'输入 ' CIKernel'!
拥有更多Swift或Core Image经验的人可以指出我正确的方向吗?即使经过一个小时的尝试和谷歌搜索,我也找不到答案......
答案 0 :(得分:3)
使用方括号创建选项字典:
return self.apply(kernel, arguments: arguments, options: [kCIApplyOptionExtent: extent])
所需参数的类型为[NSObject : AnyObject]!