I would like to draw a bitmap, manually specifying colour of every point of it (in other words, the task is to save a 2D array of RGB values to a PNG (or some other lossless true-colour bitmap format) file).
It would be also nice to have a function to print some text (with a given font of a given size) pieces on top of the image at given coordinates.
How to implement this?
You can use the Java standard library ImageIO
class. It offers a static write
method that can, for example, encode and write a RenderedImage
to an output stream in PNG format. For the RenderedImage
, you can easily use the BufferedImage
class. It offers a setRGB
method for directly manipulating the colors of individual pixels. Alternatively, you can also call BufferedImage.getGraphics()
, which returns an instance of Graphics
that you can draw any kind of shape or text on, or even whole GUI components, just like with any AWT component.
This is regular Java stuff. Scala does not offer any special wrappers for that, and I also doubt it would be worth the effort.
You should use a java library such as the Java Advanced Imaging API. It's well documented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With