/**
* Jerugraphics v 1.0
*
* See some examples of dynamically generating images are all servlet-completed,
* and the program is very long, feel is not whether from the practicality or readability is not too good.
* Here is a snippet of code that generates an image file on the command line. Is this simple and easy to use?
*
* Create a BufferedImage object, put your "painting" into this buffer,
* Then open a file, encode the image stream and enter the file, so there is a
* jpg file appears, try it ...
*
* Mender:
* Jeru Liu
* Homepage:
* http://javaren.126.com
* Email:jeru@163.net
*
* This is just a sample program, nothing practical, but very reference value.
*
*/
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;
public class Jerugraphics {
bufferedimage image;
//create JPG files to the specified path
public void Createjpg (String path) {
try {
FileOutputStream fos = new FileOutputStream (path);
bufferedoutputstream bos = new Bufferedoutputstream (FOS);
JPEGImageEncoder encoder = jpegcodec.createjpegencoder (BOS);
Encoder.encode (image);
Bos.close ();
} catch (FileNotFoundException Fnfe) {
System.out.println (FNFE);
} catch (IOException IoE) {
System.out.println (IoE);
}
}
public static void Main (string[] args) {
int width=400, height=200;
int xlength=300, ylength=150;
int count=5;
vector data=new vector ();
data.addelement (New Integer (100));
data.addelement (New Integer (120));
data.addelement (new Integer (150));
Data.addelement (New Integer (40));
data.addelement (New Integer (5));
jerugraphics JG = new Jerugraphics ();
jg.image = new BufferedImage (width, height, bufferedimage.type_int_rgb);
Graphics g = jg.image.getGraphics ();
//Draw coordinates
G.setcolor (Color.White);
g.fillrect (0, 0, width, height);
G.setcolor (Color.Blue);
G.drawline (10,height-10,10,height-10-ylength);
G.drawline (10,HEIGHT-10,10+XLENGTH,HEIGHT-10);
//Wired
int yto;
int yfrom = ((Integer) (Data.elementat (0)). Intvalue ();
for (int i=1; i<count; i++) {
yto= ((Integer) (Data.elementat (i)). Intvalue ();
G.drawline (10+i*xlength/count,height-10,10+i*xlength/count,height-15);
G.drawline (10+ (i-1) *xlength/count,yfrom,10+i*xlength/count,yto);
Yfrom=yto;
}
jg.createjpg ("d:\\aaa.jpg");
}
}