code: protected static BufferedImage createBufferedImage(int width, int height, boolean hasAlpha) {
          BufferedImage       bimage = null;
          GraphicsEnvironment ge     = GraphicsEnvironment.getLocalGraphicsEnvironment();
  
          try {
  
              // Determine the type of transparency of the new buffered image
              int transparency = Transparency.OPAQUE;
  
              if (hasAlpha) {
                  transparency = Transparency.TRANSLUCENT;
              }
  
              // Create the buffered image
              GraphicsDevice        gs = ge.getDefaultScreenDevice();
              GraphicsConfiguration gc = gs.getDefaultConfiguration();
  
              bimage = gc.createCompatibleImage(width, height, transparency);
          } catch (HeadlessException e) {
              // The system does not have a screen
          }
  
          if (bimage == null) {
  
              // Create a buffered image using the default color model
              int type = BufferedImage.TYPE_INT_RGB;
  
              if (hasAlpha) {
                  type = BufferedImage.TYPE_INT_ARGB;
              }
  
              bimage = new BufferedImage(width, height, type);
          }
  
          return bimage;
      }
docs: Create a buffered image of the given width and height, compatible with
  the alpha requirement.
  
  @param  width    the width of the new buffered image.
  @param  height   the height of the new buffered image.
  @param  hasAlpha {@code true} if the new buffered image needs to support
  alpha transparency, {@code false} otherwise.
  
  @return the newly created buffered image.