I am writing a ray tracer in java and I am trying to figure out how to write my generated image to a PNG file. So far, all the examples I have found demonstrate the use of BufferedImage to create a PNG, but they all use RGB values 0 to 255. In my code I represent each pixel colour value between 0 and 1, so for example magenta is (1, 0, 1). How can I go about writing a PNG with such values?
Thanks
If you multiply your value between 0 and 1 with 255, you’ll get a number between 0 and 255.
Note: Writing a
BufferedImageto a PNG file is very easy with the ImageIO API, it’s just one line of code: