Example usage for java.awt GraphicsConfiguration getColorModel

List of usage examples for java.awt GraphicsConfiguration getColorModel

Introduction

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

Prototype

public abstract ColorModel getColorModel();

Source Link

Document

Returns the ColorModel associated with this GraphicsConfiguration .

Usage

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
    GraphicsConfiguration[] configurations = defaultScreen.getConfigurations();
    System.out.println("Default screen device: " + defaultScreen.getIDstring());
    for (int i = 0; i < configurations.length; i++) {
        System.out.println("  Configuration " + (i + 1));
        GraphicsConfiguration c = configurations[i];
        System.out.println("  " + c.getColorModel());
        System.out.println("  " + c.getBounds());
        System.out.println("  " + c.getBufferCapabilities());
        System.out.println("  " + c.getDefaultTransform());
        System.out.println("  " + c.getDevice());
    }//w w w.ja  v  a  2  s. c o  m
}

From source file:Main.java

/**
 * Takes a snapshot of the target component.
 *
 * @param component the component to draw
 * @param usePrint  whether <tt>print()</tt> or <tt>paint()</tt> is used to grab the snapshot
 * @return a Graphics compatible image of the component
 *//*w  w w. j a  v  a  2  s. c  o  m*/
public static Image takeSnapshot(Component component, boolean usePrint) {
    BufferedImage image = null;
    GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = genv.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    if (gc.getColorModel().hasAlpha()) {
        image = gc.createCompatibleImage((int) component.getSize().getWidth(),
                (int) component.getSize().getHeight());
    } else {
        image = new BufferedImage((int) component.getSize().getWidth(), (int) component.getSize().getHeight(),
                BufferedImage.TYPE_INT_ARGB);
    }

    Graphics g = image.getGraphics();
    if (usePrint) {
        component.print(g);
    } else {
        component.paint(g);
    }
    g.dispose();

    return image;
}

From source file:GraphicsInfo.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    GraphicsConfiguration gc = g2d.getDeviceConfiguration();
    printModelType(gc.getColorModel());
    BufferedImage bi = new BufferedImage(20, 20, BufferedImage.TYPE_BYTE_INDEXED);
    Graphics2D g2d2 = bi.createGraphics();
    GraphicsConfiguration gc2 = g2d2.getDeviceConfiguration();
    printModelType(gc2.getColorModel());
    bi = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
    g2d2 = bi.createGraphics();/*from w  w w .j a  v  a 2  s.c o  m*/
    gc2 = g2d2.getDeviceConfiguration();
    printModelType(gc2.getColorModel());
    bi = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_565_RGB);
    g2d2 = bi.createGraphics();
    gc2 = g2d2.getDeviceConfiguration();
    printModelType(gc2.getColorModel());
}