In AE, icolor, irgbcolor, Win32 color, and. NET are converted to each other.

Source: Internet
Author: User

# region "will. for the irgbcolor interface in ArcGIS Engine "
'''


. for the irgbcolor interface in ArcGIS Engine,
'''
''' .. net. drawing. color Structure: argb color
'''
'''
Public Function convertcolortoirgbcolor (byval pcolor as color) as irgbcolor
dim prgbcolor as irgbcolor = new rgbcolor
prgbcolor. RGB = pcolor. B * 65536 + pcolor. g * 256 + pcolor. r
return prgbcolor
end function
# End Region

# region "will. for the icolor interface in ArcGIS Engine "
'''


. for the icolor interface in ArcGIS Engine,
'''
''' .. net. drawing. color Structure: argb color
'''
'''
Public Function convertcolortoicolor (byval pcolor as color) as icolor
dim pesricolor as icolor = new rgbcolor
pesricolor. RGB = pcolor. B * 65536 + pcolor. g * 256 + pcolor. r
return pesricolor
end function
# End Region

# region "converts the irgbcolor interface in ArcGIS Engine. net Color Structure "
'''


''' converts the irgbcolor interface in ArcGIS Engine.
'''
''' irgbcolor
''' .. net. drawing. color Structure: argb color
'''
Public Function convertirgbcolortocolor (byval prgbcolor as irgbcolor) as color
return colortranslator. fromole (prgbcolor. RGB)
end function
# End Region

# Region "converting the icolor interface in ArcGIS Engine to the color structure in. Net"
''' <Summary>
''' Converts the icolor interface in ArcGIS Engine to the color structure in. net.
''' </Summary>
''' <Param name = "pcolor"> icolor </param>
''' <Returns> the system. Drawing. Color Structure in. Net indicates the argb color. </returns>
''' <Remarks> </remarks>
Public shared function converticolortocolor (byval pcolor as icolor) as color
ReturnColortranslator. fromole (pcolor. RGB) 'Note that color. fromargb (pcolor. RGB) cannot be used here. In this function, the opposite color value of R and B is obtained.
End Function
# End Region

Note:CodeWritten in VB. NET

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 following code:

Color. fromargb (ncolorref & 255, ncolorref> 8 & 255, ncolor ref >>16 & 255 );

Note: The above code is written in C.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.