olzthebig.blogg.se

C how to convert hex value to rgb values in bmp files
C how to convert hex value to rgb values in bmp files





c how to convert hex value to rgb values in bmp files

This method (in c#, but can be easily translated to other languages) will take a percentage and list of colors and return the color on the gradient based on your percentage. If your x moves in another range (like ) you need to choose an appropriate factor instead of 2

c how to convert hex value to rgb values in bmp files

Let them be clipped to ranges and there you go. Now you have your components going from 0.0 to 2.0 (the red one) and from 2.0 to 0.0 (the green one).

c how to convert hex value to rgb values in bmp files

Assuming your x value goes from 0.00 (0%) to 1.00 (100%), you can multiply it by 2 to let it go over the 1.0 limit for color components. We can take advantage of the fact that any value above 1.0 will be read as 1.0, by maxing out our values to simplify the code. If you look carefully at the single components, you can see that we can split the range in two equal parts: in the first one we increase the red component from 0.0 to 1.0, leaving the green at 1.0 and the blue at 0.0 in the second we decrease the green component, leaving the other 2 as they are. To make it look nice, we could write a lot of code, or we could be more clever. If you just scale the green component from 0.0 (on one end) to 1.0 (on the other end) and do the same thing with the red component (but going backwards), you'll get ugly and non-uniform color distribution. Instead of the range, let's focus on the range for color components: I had the same need and I just resolved with this: m圜olor = new Color(2.0f * x, 2.0f * (1 - x), 0)







C how to convert hex value to rgb values in bmp files