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。