简体   繁体   English

在Java中将颜色隐式转换为RGB值

[英]Covert color to rgb value in java

I know a formula to convert a colour to its RGB. 我知道将颜色转换为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. 这就是我们获得单个RGB值的方式。

Using java programming 使用Java编程

int rgb2=c.getRGB();

when I compare this two rgb1 and rgb2, they show a different value. 当我比较这两个rgb1和rgb2时,它们显示不同的值。 What's wrong in my first equation. 我的第一个方程式有什么问题。 Please kindly solve my problem. 请好好解决我的问题。 Thanks 谢谢

That because the first way ignores the Alpha value of the color. 那是因为第一种方法忽略了颜色的Alpha值。
You can see that c.getAlpha() returns 255 and you don't use this value, but c.getRGB(); 您可以看到c.getAlpha()返回255,并且您没有使用此值,但是c.getRGB(); does use it, so it returns FF646464 (in hex base), which is different from 646464 . 确实使用它,因此它返回FF646464 (以十六进制表示),这与646464不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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