我使用以下代码更改UIImage的色调
UIImage *image = [UIImage imageNamed:@"Image.png"];
// Create a Core Image version of the image.
CIImage *sourceCore = [CIImage imageWithCGImage:[image CGImage]];
// Apply a CIHueAdjust filter
CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
[hueAdjust setDefaults];
[hueAdjust setValue: sourceCore forKey: @"inputImage"];
[hueAdjust setValue: [NSNumber numberWithFloat: 1.0f] forKey: @"inputAngle"];
CIImage *resultCore = [hueAdjust valueForKey: @"outputImage"];
// Convert the filter output back into a UIImage.
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef resultRef = [context createCGImage:resultCore fromRect:[resultCore extent]];
UIImage *result = [UIImage imageWithCGImage:resultRef];
CGImageRelease(resultRef);
代码工作正常,我只想找到一种方法来获取特定颜色的inputAngle的正确NSNumber值。
我也许可以:
[UIColor colorWithRed:0.89 green:0.718 blue:0.102 alpha:1.0]
文档说:
提前致谢
答案 0 :(得分:2)
这篇文章可能会回答你的问题:
Is there function to convert UIColor to Hue Saturation Brightness?
角度应该是你到达的色调值。
在这里您可以找到有关如何理解角度的一些信息:
iOS: Values for CIFilter (Hue) from Photoshop
修改强>
以下是一些基于您的示例代码:
首先让我们定义你想要过滤的颜色(对于你的inputAngle)
UIColor *myColor = [UIColor redColor]; // The color you want to filter
然后我们确定该颜色的色调值(即实际的inputAngle)
CGFloat hue;
CGFloat saturation;
CGFloat brightness;
CGFloat alpha;
[myColor getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
这是你的代码(未更改)
UIImage *image = [UIImage imageNamed:@"Image.png"];
// Create a Core Image version of the image.
CIImage *sourceCore = [CIImage imageWithCGImage:[image CGImage]];
// Apply a CIHueAdjust filter
CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
[hueAdjust setDefaults];
[hueAdjust setValue: sourceCore forKey: @"inputImage"];
这里我们使用所选颜色的确定色调值来应用滤镜
[hueAdjust setValue: [NSNumber numberWithFloat: hue] forKey: @"inputAngle"];
这是你的代码(未更改)
CIImage *resultCore = [hueAdjust valueForKey: @"outputImage"];
// Convert the filter output back into a UIImage.
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef resultRef = [context createCGImage:resultCore fromRect:[resultCore extent]];
UIImage *result = [UIImage imageWithCGImage:resultRef];
CGImageRelease(resultRef);
希望这符合您的需求。