How to change color of BufferedImage with format # 000000?

Using BufferedImage Create an image and draw it with darkGray color:

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D graphics = image.createGraphics();
Color darkGray = new Color(44, 47, 48);
graphics.setColor(darkGray);
graphics.fill(new RoundRectangle2D.Float(0, 0, image.getWidth(), image.getHeight(), ROUND_OF_CORNERS, ROUND_OF_CORNERS));

I want to change the image color using a different color presentation format, for example: # 2B2B2B (instead of the RGB format: 44, 47, 48).

+4
source share
1 answer

You can decode the hexadecimal value in Color as follows:

Color myColor = Color.decode("#2B2B2B");
+4
source

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


All Articles