为什么CIColorCube没有在我的Image上实现?

时间:2016-01-30 14:37:41

标签: ios swift core-image

我想在我的UIImage中实现CIColorCube,为此我会做下一步:

var filter = CIFilter(name: "CIColorCube")
    let sourceImage = CIImage(image: UIImage(named: "some_image.png"))
    filter!.setValue(sourceImage, forKey: kCIInputImageKey)
    filter!.setDefaults()

    var size: UInt = 64
    var floatSize = UInt(sizeof(Float))
    var cubeDataSize:size_t = Int(size * size * size * floatSize * 4)

    let colorCubeData: [Float] = [
        1, 1, 1, 1,
        1, 0, 0, 1,
        0, 1, 0, 1,
        1, 1, 0, 1,
        0, 0, 1, 1,
        1, 0, 1, 1,
        0, 1, 1, 1,
        1, 1, 1, 1
    ]
    let cubeData = NSData(bytes: colorCubeData, length: colorCubeData.count * sizeof(Float))
    let context = CIContext(options: nil)
    let outputCGImage = context.createCGImage(filter!.outputImage!, fromRect: filter!.outputImage!.extent)
    let filteredImage = UIImage(CGImage: outputCGImage)

当我对我的图像使用此滤镜时,没有任何反应。那么,我做错了什么?我有什么不对的吗?

1 个答案:

答案 0 :(得分:0)

我认为在上面的代码中你错过了这个:

filter!.setValue(cubeData, forKey: "inputCubeData")
filter!.setValue(2, forKey: "inputCubeDimension")