Some questionable utils code
Posted: Fri Apr 19, 2013 3:04 am
in Utils.cs:
If I am not mistaken - in order to blend colors it creates a (STATIC!!) bitmap, draws a gradient on it then gets a pixel from the middle of it to get the blended color?
This is the most convoluted way I can think of to blend colors, when all you have to do is the RGB intrapolation to do the same, without calling GDI stuff at all. The reason why I even found this is because each of my charts sits in its own thread and the static bmp made them conflict.
For now I just put in my own code to do the blend. But PLEASE change this in the future releases.
Code: Select all
public static Color CalcColorBlend(Color start, Color end, int percentage)
...
Rectangle rect = new Rectangle(0, 0, 100, 1);
LinearGradientBrush brush = new LinearGradientBrush(rect, start, end, LinearGradientMode.Horizontal);
if (bmp == null)
{
bmp = new Bitmap(100, 1);
}
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(brush, rect);
result = bmp.GetPixel(percentage, 0);
This is the most convoluted way I can think of to blend colors, when all you have to do is the RGB intrapolation to do the same, without calling GDI stuff at all. The reason why I even found this is because each of my charts sits in its own thread and the static bmp made them conflict.
For now I just put in my own code to do the blend. But PLEASE change this in the future releases.