Click here to Skip to main content
15,915,603 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted

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?
 
Share this answer
 
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900