![](/img/trans.png)
[英]Java: How do I detect the format and read the RGB values of each pixel from an image?
[英]convert pixel values into RGB format
我有一个像素的红色,绿色和蓝色值。 如何将它们转换为RBG格式以创建新图像? 我基本上需要一个相反的过程:
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
int rgb = ((r << 16) | ((g << 8) | b);
假设它是RGB888。 确保r,g and b
都在0-255范围内
使用java.awt.Color
类是一个很好的做法。
它将使事情变得更简单 , 更容易 。 在你的情况下,它将是:
Color myColor = new Color(red, green, blue); //Construct the color
myColor.getRGB(); //Get the RGB of the constructed color
或反过来:
Color myColor = new Color(rgb); //Construct the color with the RGB value
myColor.getRed(); //Get the separate components of the constructed color
myColor.getGreen();
myColor.getBlue();
有关更多信息,请咨询Javadocs 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.