如何将双精度转换为刻度中的颜色 [英] How to convert a double to a color in a scale

查看:83
本文介绍了如何将双精度转换为刻度中的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双数组,其值介于-0.001到0.002之间。我想将每个值转换为双色标度的颜色像素。 -0.001指定为蓝色,0.002指定为红色。中间的值是混合。



是否可以这样做?

I have an double array whose values are between -0.001 to 0.002. I want to convert the each value to a pixel of color in a two-color scale. -0.001 assign to blue and 0.002 assigns to red. values in between are blends.

Is it possible to do it?

推荐答案

是。

只需确定要进行多少阴影并将最小值映射到RGB蓝色,将最大值映射到RGB红色:中间值减少蓝色并增加红色,或者一起或者一个增加红色。



这听起来像是一个糟糕的颜色映射方案:当你引入Green时会发生什么?
Yes.
Just decide how many "shades" you are going to do and map the minimum to RGB Blue, and maximum to RGB red: the intermediate values decrease blue and increase red, either together or one then the other.

It sounds like a poor colour mapping scheme though: what happens when you introduce Green?


在这里看一下梯度计算的一种方法:http://ionicsolutions.net/2011/12/28/multicolor -gradients-an-introduction-to-with-palette-effects-effects / [ ^ ]



但是你可以使用WPF的渐变刷逻辑(甚至在Windows Forms中)来做同样有点整洁: https:/ /dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/ [ ^ ]。在你的情况下你有一个1px高的矩形。



但是还有更多的渐变插值方法,例如你想要热图。



但是,您仍需要将渐变边缘的上下限和临时值映射到渐变中的位置。但这是基础数学。
See here for one way of gradient calculation: http://ionicsolutions.net/2011/12/28/multicolor-gradients-an-introduction-to-working-with-palette-effects/[^]

However you can use WPF's gradient brush logic (even in Windows Forms) to do the same a little bit neater: https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/[^]. In your case you have a rectangle of 1px hight.

But there are even more gradient interpolation methods, if you want heatmap for example.

However, you still need to map upper and lower bound to the edges of the gradient and the interim value to a position in the gradient. But that's elementary math.


这篇关于如何将双精度转换为刻度中的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆