title: Why do I use Graphics2D to convert text to png image text with black border?
body: <p>I want to convert the text to png image first and then add the image as a watermark to the PDF, but the image text I generate has a black border:
  <a href="https://i.stack.imgur.com/IA8LX.png" rel="nofollow noreferrer">my png result</a></p>
  <p>Below is my code to generate png image:</p>
  <pre><code>public static BufferedImage textToResumeWatermark(@NotNull String text, @NotNull Font f){
  
      BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2d = img.createGraphics();
      g2d.setFont(f);
      FontMetrics fm = g2d.getFontMetrics();
      int width = fm.stringWidth(text);
      int height = fm.getHeight();
      g2d.dispose();
  
      img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      g2d = img.createGraphics();
  
      // set to transparent background
      img = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
      g2d.dispose();
      g2d = img.createGraphics();
  
      g2d.setFont(f);
      g2d.setColor(new Color(228,231,237));
      // add string content
      fm = g2d.getFontMetrics();
      g2d.drawString(text, 0, fm.getAscent());
  
      g2d.dispose();
  
      return img;
  }
  </code></pre>
  <p>Is there a problem with the process of generating the image? How should I modify the border of the text?
  The picture effect I expect is as follows:
  <a href="https://i.stack.imgur.com/M0o2t.png" rel="nofollow noreferrer">expect style</a></p>