Java 将像素值转换为RGB格式

Java 将像素值转换为RGB格式,java,Java,我有一个像素的红色,绿色和蓝色分别的值。如何将其转换为RBG格式以创建新图像?我基本上需要一个相反的过程: int red = (rgb >> 16) & 0xFF; int green = (rgb >> 8) & 0xFF; int blue = rgb & 0xFF; intrgb=((r使用java.awt.Color类是一个很好的实践。 它将使事情变得更简单和更容易。在您的情况下,它将是: Color myColor = new Col

我有一个像素的红色,绿色和蓝色分别的值。如何将其转换为RBG格式以创建新图像?我基本上需要一个相反的过程:

int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;

intrgb=((r使用
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();
有关更多信息,请参阅

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();