If you use MFC and. Net mixed programming, you will encounter this problem. If you use the control compiled by MFC, called by. net, the background color setting in the control requires color conversion.
Colorref type color value colorref Cr = RGB (123,200, 12 );
The order of the R, G, and B components is BGR.
In. net, the color is represented by the Data Type Color. This class has a function fromargb (INT, Int, INT). You can input three RGB values to a color type. There is also a toargb () function to get a 32-bit integer,
The 32-bit argb value is in bytes rggbb. 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 are respectively red, green, and blue color components.
After learning about the above content, color conversion is easy.
1. From color to colorref
Int ncolor = crcolor. toargb ();
Int Blue = ncolor & 255;
Int Green = ncolor> 8 & 255;
Int Red = ncolor> 16 & 255;
// Note that the color arrangement in colorref is BGR, and the color arrangement in the value obtained by color. toargb () is aarrggbb.
Int ncolorref = blue <16 | green <8 | red;
2. From colorref to color (note that the color arrangement in colorref is BGR, and the red weight is at the end)
Int Red = ncolorref & 255;
Int Green = ncolorref> 8 & 255;
Int Blue = ncolor ref> 16 & 255;
Color crcolor = color. fromargb (red, green, blue );
Or directly use the followingCode:
Color. fromargb (ncolorref & 255, ncolorref> 8 & 255, ncolor ref >>16 & 255 );
Note: The above code is written in C.