How to draw a bitmap using Scala?

I would like to draw a bitmap by manually specifying the color of each of its points (in other words, the task is to save a 2D array of RGB values ​​in PNG (or some other format of the bitmap format with true color)).

It would be nice to have a function to print some text (with a given font of a given size) over the image in the given coordinates.

How to implement this?

+4
source share
2 answers

You can use the Java ImageIO standard library ImageIO . It offers a static write method that can, for example, encode and write a RenderedImage to a PNG output stream. For RenderedImage you can easily use the BufferedImage class. It offers a setRGB method for directly controlling the colors of individual pixels. Alternatively, you can also call BufferedImage.getGraphics() , which returns a Graphics instance that you can draw any shape or text, or even entire GUI components, like any AWT component.

This is regular Java stuff. Scala does not offer any special wrappers for this, and I also doubt that it will be worth the effort.

+7
source

You should use a java library such as the Java Advanced Imaging API . This is well documented.

+2
source

Source: https://habr.com/ru/post/1336202/


All Articles