Java Image to BufferedImage makeBufferedImage(Image image)

Here you can find the source of makeBufferedImage(Image image)

Description

make Buffered Image

License

Open Source License

Declaration

public static BufferedImage makeBufferedImage(Image image) 

Method Source Code


//package com.java2s;
/*/*from   w  w  w.ja  v a2 s.c  o m*/
 * @(#)ImageUtil.java 1.2 04/12/06
 *
 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
 *
 * See the file "LICENSE.txt" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

import java.awt.*;
import java.awt.image.*;

public class Main {
    static Component component = new Component() {
    };
    static MediaTracker tracker = new MediaTracker(component);
    static int sid = 0;

    public static BufferedImage makeBufferedImage(Image image) {
        return makeBufferedImage(image, BufferedImage.TYPE_INT_RGB);
    }

    public static BufferedImage makeBufferedImage(Image image, int type) {
        if (!waitForImage(image)) {
            return null;
        }
        BufferedImage bim = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
        Graphics g = bim.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bim;
    }

    public static boolean waitForImage(Image image) {
        int id;
        synchronized (component) {
            id = sid++;
        }
        tracker.addImage(image, id);
        try {
            tracker.waitForID(id);
        } catch (InterruptedException e) {
            return false;
        }
        tracker.removeImage(image, id);
        return !tracker.isErrorID(id);
    }
}

Related

  1. imageToBufferedImage(Image img)
  2. imageToBufferedImage(Image img)
  3. imageToBufferedImage(Image pImage)
  4. imageToBufferedImage(Image src)
  5. makeBufferedImage(final Image image)
  6. makeBufferedImage(Image image)
  7. makeRGBABufferedImageFromImage( Image image)
  8. toBufferedImage(Image i)
  9. toBufferedImage(Image image)