首页 文章

iOS8可以使用CIFilter为UIImage的色调/饱和度/亮度设置动画吗?

提问于
浏览
2

我在看an Apple example that uses core image filters to adjust Hue/saturation/brightness的图片 . 在这种情况下,如果可以对此转换进行动画处理(逐步转换),则输入图像会感兴趣.1695898_感兴趣 .

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

我检查了Apple view programming guidelines,但没有看到任何关于动画图像或颜色的信息 .

- (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;

    }

1 回答

  • 0

    对于慢速淡化动画,您可以在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){
    
                                      }];
                 }];
    

相关问题