3
我有一个像素的红色,绿色和蓝色值分开。如何将它们转换为RBG格式以创建新图像?基本上,我需要一个相反的过程本:将像素值转换为RGB格式
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
我有一个像素的红色,绿色和蓝色值分开。如何将它们转换为RBG格式以创建新图像?基本上,我需要一个相反的过程本:将像素值转换为RGB格式
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。