Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 738
dasfsdf Avatar asked Dec 09 '25 23:12

dasfsdf


2 Answers

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.

like image 147
DonBoitnott Avatar answered Dec 11 '25 12:12

DonBoitnott


Dim decValue as String = Convert.ToInt32("FFFFFF", 16)
like image 36
Douglas Barbin Avatar answered Dec 11 '25 13:12

Douglas Barbin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!