我正在查看一个 Apple 示例,该示例使用核心图像过滤器来调整图像的色相/饱和度/亮度。在这种情况下,输入图像的属性已调整,并且另一个图像作为过滤操作的结果返回。我很感兴趣这个过渡是否可以动画(逐步过渡)。
有没有办法让我以编程方式为彩色慢慢淡入的黑白图像制作动画?
我查看了Apple 视图编程指南,但没有看到任何有关动画图像或颜色的信息。
- (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;
}