CIHueAdjust core image filter setup

2019-06-07 04:48发布

问题:

I am getting an error when I try to implement CIHueAdjust. The app terminates with an error like: -[CIImage doubleValue]: unrecognized selector sent to instance 0xd6606d0

Here is the whole project:owolf.net/uploads/StackOverflow/HueAdjustProject.zip

Here is the .m code:

- (void)viewDidLoad
{
    context = [CIContext contextWithOptions:nil];
    hueFilter = [CIFilter filterWithName:@"CIHueAdjust"];
    inputCGImage = imageView.image.CGImage;
    [super viewDidLoad];
}

- (IBAction)hueSliderValueChanged:(id)sender {
    [hueFilter setValue:[NSNumber numberWithFloat:hueSlider.value] forKey: @"inputAngle"];
    [self filterImage];
}

-(void)filterImage {
    adjustedImage = [CIImage imageWithCGImage:inputCGImage];
    [hueFilter setValue:adjustedImage forKey:@"inputAngle"];
    adjustedImage = [hueFilter outputImage];
    CGImageRef cgimg = [context createCGImage:adjustedImage fromRect:[adjustedImage extent]];
    adjustedUIImage = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);
    [imageView setImage:adjustedUIImage]; 
}

Error Log:

2012-08-16 17:14:02.062 HueAdjustProject[3333:707] -[CIImage doubleValue]: unrecognized selector sent to instance 0xd6606d0 2012-08-16 17:14:02.065 HueAdjustProject[3333:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIImage doubleValue]: unrecognized selector sent to instance 0xd6606d0' * First throw call stack: (0x3544088f 0x377e7259 0x35443a9b 0x35442915 0x3539d650 0x36b09a3f 0xed0c5 0xed017 0x3539a3fd 0x32e8fe07 0x32e8fdc3 0x32e8fda1 0x32e8fb11 0x33085d07 0x32e8f6a5 0x32e8e8a1 0x32e8e319 0x32e74695 0x32e73f3b 0x3703322b 0x35414523 0x354144c5 0x35413313 0x353964a5 0x3539636d 0x37032439 0x32ea2cd5 0xecb17 0xecabc) terminate called throwing an exception

回答1:

[hueFilter setValue:adjustedImage forKey:@"inputAngle"];

should be

[hueFilter setValue:adjustedImage forKey:@"inputImage"];