简体   繁体   中英

RGB/Hexdecimal color to Decimal Value

lets say that i want to convert the color #FFFFFF to Decimal value: 16777215 , or RGB(255,255,255) to 16777215 , how can i do it( C# or VB.net )?
i have to convert the RGB/Hexdecimal color to Decimal, because i want to convert the color to Decimal and then convert the Decimal to bytes ( BitConverter.GetBytes(DecimalValue) and the write the bytes into memoryAdress,
this website converts any color to Decimal : http://www.mathsisfun.com/hexadecimal-decimal-colors.html
(i can convert the SWF file to FLA file and the take a look at the function, But I'm sure that there are better ways and easier ways)

You can use ColorTranslator :

String knownColor = System.Drawing.ColorTranslator.ToHtml(Color.White);  //returns "White" which is reversible through FromHtml()

...or

String hexColor = System.Drawing.ColorTranslator.ToHtml(Color.FromArgb(255, 100, 100, 100));  //returns the hex value

And the inverse:

Color myColor = System.Drawing.ColorTranslator.FromHtml("FFFFFF");

To get to an Int32, just Convert it:

Int32 iColor = Convert.ToInt32("FFFFFF");

This gives you both coming and going options...simply combine them to get the desired result in whatever direction you are going.

Dim decValue as String = Convert.ToInt32("FFFFFF", 16)

我会去

int.Parse("FFFFFF", System.Globalization.NumberStyles.HexNumber)

RGB =(R * 65536)+(G * 256)+ B,(当R为红色,G为绿色且B为蓝色时)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM