WPF Color interpolation -
I am trying to color the background of a WPF control based on a panel where each color value is assigned with (Such as red = 0, darkgreen = 10, green = 20, light gran = 30) and a user-selected value (like 25) that will result in color. I should have resulted in an interpolation between color 2 closest color values (for example, for the value of 25 it should be painted between green and light green)
For this I am thinking of using existing WPF Linear Gradric Brush in; Set gridentstops, offset and color to a specified value. Is there a way to do this or should I implement my own color interpolation function?
Thank you.
Using LinearGradientBrush seems like it would be a bit overhead though there is no knowledge
I assume that there are values in your straps that are divisible by 10 for simplicity.
Public Static Color GetColor (Int Value) {int startIndex = (Value / 10) * 10; Int endIndex = startIndex + 10; Color initial color = bar [startindex]; Color end = color = bar [and index]; Float weight = (value - startindex) / (float) (and index - startindex); Return color. Form ARBB (Math) Round (Startcroller. R * (weight) + EndClorR * Weight, (Int.) Math. Round (Startcour. G * (1 - Weight) + EndClor.G * Weight), (int) math round (startcroll b * (1 - weight) + end color. B * weight);; } If the defined colors are not divisible from 10 then the argument to find the beginning and end colors will be a bit more complex.
Comments
Post a Comment