[英]Get hue value from a UIColor?
我正在使用以下代碼來更改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]
文檔說:
提前致謝
這篇文章可能會回答您的問題:
是否有將UIColor轉換為Hue Saturation Brightness的功能?
角度應該是您到達那里的色相值。
在這里,您可以找到一些有關如何理解角度的信息:
編輯
這是一些基於您的示例代碼:
首先讓我們定義您要過濾的顏色(對於您的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);
希望這符合您的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.