简体   繁体   English

sRGB到RGB颜色转换

[英]sRGB to RGB color conversion

I have sRGB numbers stored in file produced by Color.getRGB() method like this : 我将sRGB数字存储在由Color.getRGB()方法生成的文件中,如下所示:

//example for RED color
int num = Color.RED.getRGB(); // num is -65536 for RED
// save num to a file.

Now I have to read the values from that file and have to convert each number to [x,y,z] RGB format. 现在,我必须从该文件中读取值,并将每个数字转换为[x,y,z] RGB格式。 From -65536 I need to get [255,51,51] . -65536我需要获取[255,51,51]

Can anyone tell me how to do that in java? 谁能告诉我如何用Java做到这一点?

Here it is 这里是

int num = Color.RED.getRGB();
int blue =  num & 255;
int green = (num >> 8) & 255;
int red =   (num >> 16) & 255;
System.out.println("R:"+red+"\n"+"G:"+green+"\n"+"B:"+blue);
Color color = new Color(-65536);
int r = color.getRed();
int g = color.getGreen();
int b = color.getBlue();

System.out.println(String.format("%d %d %d", r, g, b));  // 255 0 0

As mentionned in the documentation , there is method in the Color class to obtain this 文档中所述,Color类中有一种方法可以获取此信息。

getRed()
getGreen()
getBleu()

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

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