我正在使用Dondragmer在此问题中提供的“旋转色调”示例代码:如何以编程方式更改UIImage的色调?
然而,我的结果与预期非常不同。我希望改变色调会产生类似于在Photoshop中改变色调的效果,但实际上这些变化并不相似。
为了说明问题,我使用了这张源图像: 在Photoshop中进行pi/4旋转会得到这个结果: 使用Dondragmer的代码我得到: 同样地,在Photoshop中进行180度旋转会得到以下结果: 但CIHueAdjust滤镜会产生:
为了说明问题,我使用了这张源图像: 在Photoshop中进行pi/4旋转会得到这个结果: 使用Dondragmer的代码我得到: 同样地,在Photoshop中进行180度旋转会得到以下结果: 但CIHueAdjust滤镜会产生:
我的代码:
- (CGImageRef)changeHueOfImage(CGImageRef)source By:(NSInteger)angle
{
CIImage *image = [CIImage imageWithCGImage:source];
// Convert degrees to radians
CGFloat angleRadians = GLKMathDegreesToRadians(angle);
// Use the Core Image CIHueAdjust filter to change the hue
CIFilter *hueFilter = [CIFilter filterWithName:@"CIHueAdjust"];
[hueFilter setDefaults];
[hueFilter setValue:image forKey:@"inputImage"];
[hueFilter setValue:[NSNumber numberWithFloat:angleRadians] forKey:@"inputAngle"];
image = [hueFilter outputImage];
// Save the modified image
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef result = [context createCGImage:image fromRect:[image extent]];
return result;
}
我的问题:
- 我是否误解了CIHueAdjust滤镜的作用?
- 我需要考虑亮度和饱和度如何影响滤镜吗?
- 我该如何复制Photoshop的行为?
- 总的来说,为什么结果会如此不同?