0

I am trying to read a PNG, draw a circle and write the image to the same or a different file. But the new image is identical to the input image. What am I missing? Thank you.

File file = new File("Screenshot.png");
BufferedImage image = ImageIO.read(file);

Graphics2D g2d = image.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.RED);
g2d.fillOval(center.x - radius, center.y - radius, radius * 2, radius * 2);
g2d.dispose();

File outFile = new File("new.png");
ImageIO.write(image, "png", outFile);

EDIT: I did find that linked question myself, but still do not understand how to modify the image I read from file using ImageIO. The example from the answer showing there is creating a BufferedImage from the JPanel.

derrdji
  • 12,661
  • 21
  • 68
  • 78

0 Answers0