如何更改#000000格式的BufferedImage的颜色?

How to change the color of BufferedImage with #000000 format?

我使用 BufferedImage 创建图像并用 darkGray 颜色绘制它:

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));

我想通过使用另一种颜色表示格式来更改图像的颜色,例如:#2B2B2B(而不是 RGB 格式:44、47、48)。

您可以像这样将十六进制值解码为颜色:

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