计算机二级

3773考试网计算机等级考试计算机二级正文

直接用java命令行动态生成jpg文件方法

来源:fjzsksw.com 2010-7-19 14:33:47

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();

  // 画坐标

  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);

  // 连线

  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");

  }

  }

 

 

 

上一页  [1] [2] 

触屏版 电脑版
3773考试网 琼ICP备12003406号-1