C# 不同值的色调
我想要一些关于如何在 C# 中完成以下任务的建议。我想绘制一个“颜色”,确切的颜色将由属性值决定,为了这个例子,我们假设它是一个百分比。
理想情况下,我希望用户指定五种颜色。
Negative MAX
Negative MIN
Even
Positive MIN
Positive MAX
用户仅指定每个级别的颜色,而不是确定最小和最大的值。
使用这些数据,我希望能够根据百分比计算颜色。即 57% 将导致色调介于 Positive MIN 和 Positive MAX 之间。如有任何帮助或建议,我们将不胜感激。
I would like some advice on how to accomplish the following within C#. I would like to plot a "color", the exact color will be determined by a property value, for the sake of this example let's assume it's a percentage.
Ideally I'd like the user to specify five colors.
Negative MAX
Negative MIN
Even
Positive MIN
Positive MAX
The user is only specifying colors for each level, not the value which determines Min and Max.
Using this data, I would like to be able to calculate a color based on a percentage. i.e. 57% would result in a color hue in between Positive MIN and Positive MAX. Any help or advice for this is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在两种颜色之间进行插值,您只需对每个颜色通道进行插值。
要沿比例进行插值,您需要确定“步长”具有的确切百分比值,并将目标值投影为两个颜色步长之间的分数。
To interpolate between two colors you just interpolate each color channel
To interpolate along your scale you need to decide what exact percentage values your "steps" have and project your target value that a fraction between two of those color steps.
使用复制的函数从这里< /a>,您可以将色调转换回 RGB 颜色。该函数假设所有输入和输出的比例为 0..1,因此您需要将 color.GetHue() 除以 255。该函数下面是一些使用一组百分比的示例代码;在您选择的 UI 中实现 DisplayColor 以查看结果。
Using the function copied from here, you can convert the hues back into RGB colors. This function assumes has all inputs and outputs in on a 0..1 scale, so you'll need to divide by color.GetHue() by 255. Below the function is some sample code using a set of percentages; implement DisplayColor in the UI of your choice to see the results.