So right now I have a number between 0 and 2^24, and I need to map it to three RGB values. I'm having a bit of trouble on how I'd accomplish this. Any assistance is appreciated.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You can use the
BitConverter
class to get the bytes from the int:The array will have four bytes. The first three bytes contain your number:
You can do
and then use
c.R
,c.G
andc.B
for Red, Green and Blue values respectivelyDepending on which color is where, you can use bit shifting to get the individual colors like this:
The above expression assumes
0x00RRGGBB
but your colors might be0x00BBGGRR
in which case just change the16, 8, 0
values around.This also uses
System.Drawing.Color
instead ofSystem.Windows.Media.Color
or your own color class. That depends on the application.the above code works grate. just a small correction, need to swap b and r as below.