我正在查看图片的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;
}
答案 0 :(得分: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){
}];
}];