【问题标题】:iOS8 can I animate hue/saturation/brightness of UIImage using CIFilter?iOS8 我可以使用 CIFilter 为 UIImage 的色调/饱和度/亮度设置动画吗?
【发布时间】:2014-10-09 12:08:47
【问题描述】:

我正在查看图片的an Apple example that uses core image filters to adjust Hue/saturation/brightness。在这种情况下,输入图像已调整其属性,并且另一个图像作为过滤操作的结果返回。我很感兴趣这个过渡是否可以动画化(逐步过渡)。

有没有办法让我以编程方式为彩色逐渐淡入的黑白图像制作动画?

我查看了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;

    }

【问题讨论】:

  • 你最终解决了吗?我也对此感兴趣。

标签: ios objective-c ios8 cifilter ciimage


【解决方案1】:

对于缓慢淡入淡出的动画,您可以使用 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){

                                  }];
             }];

【讨论】:

  • 感谢@Harsh Thakur,它节省了很多时间
猜你喜欢
  • 2021-09-06
  • 2011-11-26
  • 2014-07-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2012-01-31
  • 2018-04-01
  • 2013-03-03
相关资源
最近更新 更多