KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ImagePlotter


1 import java.awt.image.BufferedImage JavaDoc;
2 import java.io.File JavaDoc;
3 import java.io.IOException JavaDoc;
4
5 import javax.imageio.ImageIO JavaDoc;
6
7 import jcckit.Graphics2DPlotCanvas;
8 import jcckit.data.DataPlot;
9 import jcckit.util.ConfigParameters;
10 import jcckit.util.PropertiesBasedConfigData;
11
12 /**
13  * @author Franz-Josef Elmer
14  */

15 public class ImagePlotter
16 {
17   public static void main(String JavaDoc[] args) throws IOException JavaDoc
18   {
19     System.getProperties().setProperty("java.awt.headless", "true");
20
21     // Handles the commandline argument
22
if (args.length < 3)
23     {
24       System.out.println("Usage: java -cp classycle.jar ImagePlotter "
25                          + "<properties file> <width> <height>");
26       System.exit(0);
27     }
28     String JavaDoc propertiesFile = args[0];
29     int width = Integer.parseInt(args[1]);
30     int height = Integer.parseInt(args[2]);
31
32     // Sets up a Graphics2DPlotCanvas
33
ConfigParameters config
34         = new ConfigParameters(new PropertiesBasedConfigData(propertiesFile));
35     Graphics2DPlotCanvas plotCanvas = new Graphics2DPlotCanvas(config);
36     plotCanvas.connect(DataPlot.create(config));
37     plotCanvas.setDoubleBuffering(false);
38
39     // Draws the chart into a off-screen image
40
System.getProperties().setProperty("java.awt.headless", "true");
41     BufferedImage JavaDoc image
42         = new BufferedImage JavaDoc(width, height, BufferedImage.TYPE_INT_RGB);
43     plotCanvas.draw2DInto(image);
44
45     // Writes the off-screen image into a PNG file
46
ImageIO.write(image, "png", new File JavaDoc(propertiesFile + ".png"));
47   }
48 }
49
Popular Tags