NEKIBUR RAHMAN
NEKIBUR RAHMAN

Reputation: 212

Covert color to rgb value in java

I know a formula to convert a colour to its RGB. Eg.

Color c=new Color(100,100,100);
Int rgb1= c.getRed()*65536+c.getGreen()*256+c.getBlue();

This is how we get single RGB value.

Using java programming

int rgb2=c.getRGB();

when I compare this two rgb1 and rgb2, they show a different value. What's wrong in my first equation. Please kindly solve my problem. Thanks

Upvotes: 0

Views: 190

Answers (1)

TDG
TDG

Reputation: 6151

That because the first way ignores the Alpha value of the color.
You can see that c.getAlpha() returns 255 and you don't use this value, but c.getRGB(); does use it, so it returns FF646464 (in hex base), which is different from 646464.

Upvotes: 1

Related Questions