/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package medusa.display;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 * Convenience for creating screenshots
 * @author Sean
 */
public class ScreenShotUtility {

    
     public static BufferedImage getScreenshot(BasicGraphPanel panel){
        // param = 0 for jpg, = 1 for png
        Component comp=panel.getComponent(0);
        //int w = panelWidth;
        //int h = panelHeight;
        Dimension d = panel.getSize();
        int w = (int)d.getWidth();
        int h = (int)d.getHeight();
        BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        
        Graphics2D g2 = im.createGraphics();
        comp.paint(g2);
        g2.dispose();
        //im contains pixel data, now
        
        //standard code:
        return im;
    }
     
     public static void saveImage(){
         
     }
}

 

Ads help maintain this website.