GraphicsUtilities { public static void clear(Image img) { Graphics g = img.getGraphics(); try { if (g instanceof Graphics2D) { ((Graphics2D) g).setComposite(AlphaComposite.Clear); } else { g.setColor(new Color(0, 0, 0, 0)); } g.fillRect(0, 0, img.getWidth(null), img.getHeight(null)); } finally { g.dispose(); } } private  GraphicsUtilities(); static BufferedImage convertToBufferedImage(Image img); static BufferedImage createColorModelCompatibleImage(BufferedImage image); static BufferedImage createCompatibleImage(BufferedImage image); static BufferedImage createCompatibleImage(BufferedImage image,
                                                      int width, int height); static BufferedImage createCompatibleImage(int width, int height); static BufferedImage createCompatibleTranslucentImage(int width,
                                                                 int height); static BufferedImage loadCompatibleImage(InputStream in); static BufferedImage loadCompatibleImage(URL resource); static BufferedImage toCompatibleImage(BufferedImage image); static BufferedImage createThumbnailFast(BufferedImage image,
                                                    int newSize); static BufferedImage createThumbnailFast(BufferedImage image,
                                                    int newWidth, int newHeight); static BufferedImage createThumbnail(BufferedImage image,
                                                int newSize); static BufferedImage createThumbnail(BufferedImage image,
                                                int newWidth, int newHeight); static int[] getPixels(BufferedImage img,
                                  int x, int y, int w, int h, int[] pixels); static void setPixels(BufferedImage img,
                                 int x, int y, int w, int h, int[] pixels); static void clear(Image img); static void tileStretchPaint(Graphics g, 
                JComponent comp,
                BufferedImage img,
                Insets ins);  }
@Test public void testClear() { BufferedImage img = GraphicsUtilities.createCompatibleImage(1, 1); GraphicsUtilities.clear(img); assertThat(GraphicsUtilities.getPixels(img, 0, 0, 1, 1, null)[0], is(0)); }