I have two dimensional matrix which stores values between 0 to 1. I want to plot these values as levels of gray scale.
If the value is 1, it should be drawn as white.
If the value is 0, it should be drawn as black.
How would I do that in java?
I tried the classes: Color and BufferedImage, but I could not figure it out.
To create an image and set the pixels:
coloris an int, in this case, inARGBformat (top byte is alpha, then red byte, green byte, blue byte). Since you’re doing greyscale, you want R, G and B to be the same value. You don’t want alpha, so you should set that top byte to 0xFF.See:
BufferedImage.setRGB()