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

标签 ios objective-c ios8 cifilter ciimage

我正在查看 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 中的核心动画

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){

                                  }];
             }];

关于iOS8 我可以使用 CIFilter 为 UIImage 的色调/饱和度/亮度设置动画吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25331788/

相关文章:

ios - 如何使用键盘 "Go"像 Swift 2 中的 UIButton 一样提交 UITextFields

objective-c - 以编程方式添加 UIButton 不会显示

ios - 具有自定义 UTI 的 iCloud 文档选取器

ios - 动态 Storyboard或 Xibs/Nibs

ios - Parse Push Notifications 可以针对特定的 iOS 吗?

objective-c - "import <XYZ/XYZ.h>"是什么意思

ios - 是否可以从 Websheet.app 内部打开到 Safari 的链接

objective-c - 是否可以判断正在加载的网页是远程的还是本地的?

iphone - AFNetworking:返回 200 且无内容时运行失败 block

iphone - 如何检查是否有任何应用程序与文件扩展名相关联