【问题标题】:How to change the color of BufferedImage with #000000 format?如何更改#000000 格式的BufferedImage 的颜色?
【发布时间】:2015-07-21 09:33:41
【问题描述】:

使用 BufferedImage 创建一个图像并用深灰色绘制它:

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

【问题讨论】:

  • 当我传递字符串“6FE291”时,我收到一个异常:java.lang.NumberFormatException:对于输入字符串:“6FE291”

标签: java colors colorbox bufferedimage


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-19
    • 2021-10-02
    • 1970-01-01
    • 2020-08-03
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    相关资源
    最近更新 更多