by 4/16/2004 02:38:00 PM 0 comments

Creating an image from SGT in java

JPlotLayout jpl; 
// initialize and add plots to jpl ... ommitted here.

// Get graphic
int width = jpl.getWidth();
int height = jpl.getHeight();
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();

// Save to a file
try {
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("some.jpg"));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncoderParam param = encoder.getDefaultJPEGEncoderParam(img);
    int quality = 100;
    quality = Math.max(0, Math.min(quality, 100));
    param.setQuality((float) quality/100F, false);
catch (IOException e) {
    // Log or deai with exception

Brian Schlining


Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.