If you are using MFC with. NET programming, you will encounter this problem, the control written through MFC, by. NET invocation, the setting of the background color in the control requires a color conversion.
If you are using MFC with. NET programming, you will encounter this problem, the control written through MFC, by. NET invocation, the setting of the background color in the control requires a color conversion.
The value of the COLORREF type color COLORREF cr=rgb (123,200,12);
The order of three components of R, G and B is BGR.
. NET color is represented by the data type color, which has a function FromArgb (int,int,int), which can be worth to a color type by entering RGB three. There's also a ToArgb () function that gets a 32-bit integer value,
The byte order of the 32-bit ARGB value is AARRGGBB. The highest valid byte (MSB) represented by AA is the alpha component value. The second, third, and fourth bytes represented by RR, GG, and BB, respectively, are red, green, and blue color components, and the color conversion is simple.
1, from color to COLORREF
int ncolor = Crcolor.toargb ();
int blue = ncolor & 255;
int green = Ncolor >> 8 & 255;
int red = Ncolor >> & 255;
Note that the color arrangement in the COLORREF is BGR, and the color arrangement of the values obtained by Color.toargb () is AARRGGBB
int ncolorref = Blue << 16 | Green << 8 | Red
2, from COLORREF to color (note that the COLORREF color arrangement is BGR, red component in the last side)
int Red=ncolorref & 255;
int green= ncolorref >> 8 & 255;
int blue= ncolor ref>> & 255;
Color Crcolor=color.fromargb (Red,green,blue);
or directly through the following code:
Color.FromArgb (Ncolorref & 255, Ncolorref >> 8 & 255, Ncolor ref>> & 255);
Note: The above code is written using C #.