UIColor 从 RGB 转换为 HSV ,将亮度设置为 UIColor
在我的应用程序中,我尝试用不同的颜色进行绘制。我有自己的颜色选择器,但我想添加到此选择器滑块以提高颜色亮度。对于学生:我选择一种在视图中某处显示的颜色作为背景颜色,并且我想为该颜色添加滑块,该滑块将从 1 滑动到 0 并更改颜色的亮度并在窗口中显示颜色。所以我想问一下有没有什么可行的方法可以转换。
在我的项目中,我使用这个:
CGContextSetRGBStrokeColor(current, R, G, B, A);
所以每当我滑动滑块时,我都需要更改颜色的亮度,因此我需要将我的 UIColor
- 表示为 RGB 转换为 HSV,然后再转换回 RGB 以便使用再来一次。
是否存在 RGB 到 HSV 转换算法,或者 iOS 5 或 Xcode4 中是否有?
In my app I am trying to draw with different colors. I have my own color picker, but I want to add to this picker slider for color brightness. For understudying : I choose a color which is displayed somewhere in view as background color and to this color I want add slider which will slide from 1 to 0 and change brightness of the color and displays the color in window. Therefore I want to ask if there is any possible way how to convert.
in my project I use this :
CGContextSetRGBStrokeColor(current, R, G, B, A);
so anytime I slide the slider I need to change the brightness of the color, therefore I need to convert my UIColor
- represented as RGB to HSV and than back to RGB for using it one more time.
Does exist any RGB to HSV conversion algorithm or is there any in iOS 5 or Xcode4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不清楚在你原来的问题中你是否真的想要“亮度”或阿尔法。 RGB 和 HSV 配色方案完全不同。
如果我正确地解释了您的意图:
如果您只想控制 RGB 颜色的 Alpha 通道,则无需从 RGB 转换为 HSV 再转换回 RGB。
最简单、最有效的方法要实现您想要做的,只需添加一个 alpha 滑块并从中获取输出来更改颜色透明度。
It's not clear to me if in your original question you really want "brightness" or alpha. RGB and HSV color schemes are completely different.
If I interpret your intent correctly:
You do not need to convert from RGB to HSV and back to RGB if all you want to do is control the alpha channel for an RGB color.
The simplest and most efficient way to achieve what you want to do is to simply add a slider for alpha and take the output from that to change color transparency.