code: static void clearImage(BufferedImage img) {
          Graphics2D g2 = img.createGraphics();
  
          g2.setComposite(AlphaComposite.Clear);
          g2.fillRect(0, 0, img.getWidth(), img.getHeight());
          g2.dispose();
      }
docs: Clear a transparent image to 100% transparent
  
  @param img The image to clear