Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;

import java.awt.image.*;

public class Main {
    public static Image getImage(Component c) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();

        // Create an image that supports transparent pixels
        BufferedImage bImage = gc.createCompatibleImage(c.getWidth(), c.getHeight(), Transparency.BITMASK);

        /*
         * And now this is how we get an image of the component
         */
        Graphics2D g = bImage.createGraphics();

        // Then use the current component we're in and call paint on this
        // graphics object
        c.paint(g);
        return bImage;
    }
}