Does Java have a Bitmap class?

I searched google for things like "Java Bitmap", "Create Java Bitmap", etc. and did not seem to find much information. Of all the sample code, it looks like all the bitmap libraries are third-party or for Android.

What I want to do is very simple. I want to create a small bitmap, possibly 10x80, and be able to color each pixel on (x, y). I want to make a small, I guess, color bar that will show the position of the positions in the queue by color.

Are there any built-in libraries for this?

+8
source share
2 answers

There is a class java.awt.image.BufferedImage . This has pixel-specific get / set methods. http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html

+10
source

Here is an example of creating and writing in pixels using BufferedImage:

 BufferedImage image = new BufferedImage(10, 80, BufferedImage.TYPE_4BYTE_ABGR); image.setRGB(5, 20, Color.BLUE.getRGB()); 

The third parameter in the image is a type that can vary depending on your use, but for basic solid colors, the result shown is good. SetRGB uses an internal color representation, so you can simply use the color constant directly.

You probably don't want to use VolatileImage, because the benefits in custom Java implementations are dubious. See fooobar.com/questions/1044315 / ... why it might not help.

See the image of Oracle turorial for reference. It explains both your options and how you interact with them.

+5
source

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


All Articles