I a have the red, green and blue values of a pixel seperately. How to convert them into RBG format to create a new image? I basically need a reverse process for this:
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
int rgb = ((r << 16) | ((g << 8) | b);
assuming it's RGB888. Make sure r,g and b
are all in the 0-255 range
It's a great practice to use the java.awt.Color
class instead.
It will make the things simpler and easier . In your case it would be:
Color myColor = new Color(red, green, blue); //Construct the color
myColor.getRGB(); //Get the RGB of the constructed color
Or the inverse:
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();
For more info, consult the Javadocs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.