4

Using BufferedImage I create an image and paint 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 color of image by using another format of color presentation like: #2B2B2B (instead of RGB format: 44, 47, 48).

Dylan
  • 935
  • 1
  • 11
  • 24
  • When I pass the String "6FE291" I receve an Exception: java.lang.NumberFormatException: For input string: "6FE291" – Dylan Jul 21 '15 at 12:47

1 Answers1

4

You can decode a hex value to a Color like this:

Color myColor = Color.decode("#2B2B2B");
Stefan
  • 12,108
  • 5
  • 47
  • 66