我已经尝试过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>