Example usage for java.awt GraphicsConfiguration createCompatibleVolatileImage

List of usage examples for java.awt GraphicsConfiguration createCompatibleVolatileImage

Introduction

In this page you can find the example usage for java.awt GraphicsConfiguration createCompatibleVolatileImage.

Prototype

public VolatileImage createCompatibleVolatileImage(int width, int height, ImageCapabilities caps)
        throws AWTException 

Source Link

Document

Returns a VolatileImage with a data layout and color model compatible with this GraphicsConfiguration , using the specified image capabilities.

Usage

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }// w w w  . j  a v a2s .  co  m

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities());
    } catch (Exception e) {
        // The system does not have a screen
    }
    return bimage;
}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 *
 * @param width//from   w  w  w . j av a2  s .  c  o m
 * @param height
 * @param transparency
 * @return
 */
public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) {
    GraphicsConfiguration gc = getGraphicsConfiguration();
    VolatileImage img = gc.createCompatibleVolatileImage(width, height, transparency);
    Logger.getLogger(getClass().getName()).log(Level.INFO, "Using accelerated images: {0}",
            gc.getImageCapabilities().isAccelerated());
    Logger.getLogger(getClass().getName()).log(Level.INFO, "Using true volatile images: {0}",
            gc.getImageCapabilities().isTrueVolatile());
    return img;
}