CIColorMatrix过滤器不适用于ImageView

时间:2013-09-24 08:54:33

标签: iphone ios cifilter ciimage

我已经尝试了CIColorMatrix但似乎它没有应用于代码。

我已经使用日志附加了代码,似乎过滤器值正确显示,但它未应用于图像。

以下是代码和日志:

- (IBAction)filterImage:(id)sender {

    CIImage *rawImageData;
    rawImageData =[[CIImage alloc] initWithImage:self.imageView.image];

    CIFilter *filter = [CIFilter filterWithName:@"CIColorMatrix"];
    [filter setDefaults];

    [filter setValue:rawImageData forKey:kCIInputImageKey];

    [filter setValue:[CIVector vectorWithX:1 Y:0 Z:0 W:0] forKey:@"inputRVector"];
    [filter setValue:[CIVector vectorWithX:0 Y:1 Z:0 W:0] forKey:@"inputGVector"];
    [filter setValue:[CIVector vectorWithX:0 Y:0 Z:1 W:0] forKey:@"inputBVector"];
    [filter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:1] forKey:@"inputAVector"];
    [filter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:0] forKey:@"inputBiasVector"];

    CIImage *filteredImageData  = [filter outputImage];
    CIContext *context = [CIContext contextWithOptions:nil];
    UIImage *filteredImage = [UIImage imageWithCGImage:
         [context createCGImage:filteredImageData fromRect:filteredImageData.extent]];
    self.imageView.image = filteredImage;    
}

日志:

(lldb) po filter
<CIColorMatrix: inputImage=<CIImage: 0x8d83fc0 extent [0 0 153 95]> inputRVector=[1 0 0 0] inputGVector=[0 1 0 0] inputBVector=[0 0 1 0] inputAVector=[0 0 0 1] inputBiasVector=[0 0 0 0]>

(lldb) po rawImageData
<CIImage: 0x8d83fc0 extent [0 0 153 95]>

(lldb) po filteredImageData
<CIImage: 0x8d83fc0 extent [0 0 153 95]>

(lldb) po filteredImage
<UIImage: 0x8d1f760>

0 个答案:

没有答案