简体   繁体   中英

iOS8 can I animate hue/saturation/brightness of UIImage using CIFilter?

I'm looking at an Apple example that uses core image filters to adjust Hue/saturation/brightness of an image. In this case the input image has it's properties adjusted, and another image is returned as a result of the filter operation. I'm interested if this transition can be animated (step by step transition).

Is there a way for me to programmatically animate a black and white image having color slowly fading in?

I checked the Apple view programming guidelines , but don't see anything about animating images or colors.

- (void)hueChanged:(id)sender
{
    CGFloat hue = [hueSlider value];
    CGFloat saturation = [saturationSlider value];
    CGFloat brightness = [brightnessSlider value];

    // Update labels

    [hueLabel setText:[NSString stringWithFormat:NSLocalizedString(@"Hue: %f", @"Hue label format."), hue]];
    [saturationLabel setText:[NSString stringWithFormat:NSLocalizedString(@"Saturation: %f", 

    @"Saturation label format."), saturation]];
        [brightnessLabel setText:[NSString stringWithFormat:NSLocalizedString(@"Brightness: %f", @"Brightness label format."), brightness]];

        // Apply effects to image


        dispatch_async(processingQueue, ^{
            if (!self.colorControlsFilter) {
                self.colorControlsFilter = [CIFilter filterWithName:@"CIColorControls"];
            }
            [self.colorControlsFilter setValue:self.baseCIImage forKey:kCIInputImageKey];
            [self.colorControlsFilter setValue:@(saturation) forKey:@"inputSaturation"];
            [self.colorControlsFilter setValue:@(brightness) forKey:@"inputBrightness"];

            CIImage *coreImageOutputImage = [self.colorControlsFilter valueForKey:kCIOutputImageKey];

            if (!self.hueAdjustFilter) {
                self.hueAdjustFilter = [CIFilter filterWithName:@"CIHueAdjust"];
            }
            [self.hueAdjustFilter setValue:coreImageOutputImage forKey:kCIInputImageKey];
            [self.hueAdjustFilter setValue:@(hue) forKey:@"inputAngle"];

            coreImageOutputImage = [self.hueAdjustFilter valueForKey:kCIOutputImageKey];

            CGRect rect = CGRectMake(0,0,self.image.size.width,self.image.size.height);
            CGImageRef cgImage = [self.context createCGImage:coreImageOutputImage fromRect:rect];
            UIImage *image = [UIImage imageWithCGImage:cgImage];
            CGImageRelease(cgImage);

            dispatch_async(dispatch_get_main_queue(), ^{
                [imageView setImage:image];
            });
        });

    //    imageView.center = self.view.center;
    //    imageView.frame = self.view.frame;

    }

For slowly fade animations you can use core animations in IOS

theView.alpha = 0;
[UIView animateWithDuration:1.0
             animations:^{

                  //Apply effects to image here

                 theView.center = midCenter;
                 theView.alpha = 1;


             }
             completion:^(BOOL finished){
                 [UIView animateWithDuration:1.0
                                  animations:^{
                                      //Apply effects to image here
                                  }
                                  completion:^(BOOL finished){

                                  }];
             }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM