dasfsdf
dasfsdf

Reputation: 25

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)

Upvotes: 2

Views: 8191

Answers (4)

RGB = (R*65536)+(G*256)+B , (when R is RED, G is GREEN and B is BLUE)

Upvotes: 0

DonBoitnott
DonBoitnott

Reputation: 11035

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.

Upvotes: 4

t3hn00b
t3hn00b

Reputation: 912

I would go with

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

Upvotes: 3

Douglas Barbin
Douglas Barbin

Reputation: 3615

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

Upvotes: 3

Related Questions