code: public static BufferedImage toCompatibleImage(BufferedImage image) {
          if (isHeadless()) {
              return image;
          }
  
          if (image.getColorModel().equals(
                  getGraphicsConfiguration().getColorModel())) {
              return image;
          }
  
          BufferedImage compatibleImage =
                  getGraphicsConfiguration().createCompatibleImage(
                      image.getWidth(), image.getHeight(),
                      image.getTransparency());
          Graphics g = compatibleImage.getGraphics();
          
          try {
              g.drawImage(image, 0, 0, null);
          } finally {
              g.dispose();
          }
  
          return compatibleImage;
      }
docs: <p>Return a new compatible image that contains a copy of the specified
  image. This method ensures an image is compatible with the hardware,
  and therefore optimized for fast blitting operations.</p>
  
  <p>If the method is called in a headless environment, then the returned
  <code>BufferedImage</code> will be the source image.</p>
  
  @see #createCompatibleImage(java.awt.image.BufferedImage)
  @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
  @see #createCompatibleImage(int, int)
  @see #createCompatibleTranslucentImage(int, int)
  @see #loadCompatibleImage(java.net.URL)
  @param image the image to copy into a new compatible image
  @return a new compatible copy, with the
  same width and height and transparency and content, of <code>image</code>