Example usage for java.awt Component createImage

List of usage examples for java.awt Component createImage

Introduction

In this page you can find the example usage for java.awt Component createImage.

Prototype

public Image createImage(int width, int height) 

Source Link

Document

Creates an off-screen drawable image to be used for double buffering.

Usage

From source file:Main.java

public static BufferedImage createImage(Component comp) {
    if (comp == null)
        return null;

    BufferedImage image = (BufferedImage) comp.createImage(comp.getWidth(), comp.getHeight());
    Graphics g = image.createGraphics();
    comp.paintAll(g);/*  w ww  . j a  va2  s.  c om*/
    return image;
}

From source file:no.geosoft.cc.io.GifEncoder.java

/**
 * Write AWT/Swing component to GIF file.
 * //from   ww  w  . j a  va2s . co  m
 * @param image  Image to write.
 * @param file   File to erite to.
 */
public static void writeFile(Component component, File file) throws AWTException, IOException {
    Image image = component.createImage(component.getWidth(), component.getHeight());
    Graphics graphics = image.getGraphics();
    component.printAll(graphics);

    GifEncoder.writeFile(image, file);
}