Here you can find the source of imageToBufferedImage(Image img)
public static BufferedImage imageToBufferedImage(Image img)
//package com.java2s; /* autonoesis -- Automatic Movie Processor * Copyright (C) 2008 Shuichi Kurabayashi <Shuichi.Kurabayashi@acm.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version./*w ww. j a va2 s .c om*/ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.awt.Component; import java.awt.Image; import java.awt.MediaTracker; import java.awt.image.BufferedImage; import java.awt.image.PixelGrabber; public class Main { public static BufferedImage imageToBufferedImage(Image img) { try { MediaTracker tracker = new MediaTracker(new Component() { private static final long serialVersionUID = 1L; }); tracker.addImage(img, 0); tracker.waitForAll(); } catch (InterruptedException ie) { ie.printStackTrace(); return null; } BufferedImage bimg = null; int w = img.getWidth(null); int h = img.getHeight(null); int[] pixels = new int[w * h]; PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixels, 0, w); try { pg.grabPixels(); } catch (InterruptedException ie) { ie.printStackTrace(); return null; } bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); bimg.setRGB(0, 0, w, h, pixels, 0, w); return bimg; } }