如何应用AWT在本地生成图片(任何格式的图片) 不可能的只能生成三种格式的图片就是:jpeg,gif和png 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一步:创建一个Java Bean用来生成jpg文件 源程序如下: //生成图片的 Java Bean //作者:崔冠宇 //日期:2001-08-24 import java.io.*; import java.util.*; import com.sun.image.codec.jpeg.*; import java.awt.image.*; import java.awt.*; public class ChartGraphics { BufferedImage image; public void createImage(String fileLocation) { try { FileOutputStream fos = new FileOutputStream(fileLocation); BufferedOutputStream bos = new BufferedOutputStream(fos); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos); encoder.encode(image); bos.close(); } catch(Exception e) { System.out.println(e); } } public void graphicsGeneration(int h1,int h2,int h3,int h4,int h5) { final int X=10; int imageWidth = 300;//图片的宽度 int imageHeight = 300;//图片的高度 int columnWidth=30;//柱的宽度 int columnHeight=200;//柱的最大高度 ChartGraphics chartGraphics = new ChartGraphics(); chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics graphics = chartGraphics.image.getGraphics(); graphics.setColor(Color.white); graphics.fillRect(0,0,imageWidth,imageHeight); graphics.setColor(Color.red); graphics.drawRect(X+1*columnWidth, columnHeight-h1, columnWidth, h1); graphics.drawRect(X+2*columnWidth, columnHeight-h2, columnWidth, h2); graphics.drawRect(X+3*columnWidth, columnHeight-h3, columnWidth, h3); graphics.drawRect(X+4*columnWidth, columnHeight-h4, columnWidth, h4); graphics.drawRect(X+5*columnWidth, columnHeight-h5, columnWidth, h5); chartGraphics.createImage("D:\\temp\\chart.jpg"); } } 饼型图我对你这个图形做法比较感兴趣,我不知道你能不能只用jdk1.1版本绘制一个饼图,不要用graphic2D等工具, 把你的这个饼图做转成image,再把这个对象序列化保留,到你要用时再把它读出来。这是一种思路,好像不合你的要求 怎么使用io包中的Ramdom随即存储 求:这个正则表达式怎么写 如何将int型的数据转化为byte型数据 急!恳请各位大侠!想用java+Mysql做数据库,在线等!!! 这是我按照书写的怎么还会有错啊? applet问题 关于lookup jndi的问题 我的APPLET没有问题,嵌入网页后,为什么用APPLETVIEWER可以运行,但用IE就不行 谁有javaAPI,或能到那里DOWNLOAD? 键盘事件捕捉问题 《java实例技术手册》的疑问??? java怎样连接ACCESS数据库
//作者:崔冠宇
//日期:2001-08-24
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*; public class ChartGraphics {
BufferedImage image;
public void createImage(String fileLocation) {
try {
FileOutputStream fos = new FileOutputStream(fileLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
bos.close();
} catch(Exception e) {
System.out.println(e);
}
} public void graphicsGeneration(int h1,int h2,int h3,int h4,int h5) { final int X=10;
int imageWidth = 300;//图片的宽度
int imageHeight = 300;//图片的高度
int columnWidth=30;//柱的宽度
int columnHeight=200;//柱的最大高度 ChartGraphics chartGraphics = new ChartGraphics();
chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
Graphics graphics = chartGraphics.image.getGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0,0,imageWidth,imageHeight);
graphics.setColor(Color.red);
graphics.drawRect(X+1*columnWidth, columnHeight-h1, columnWidth, h1);
graphics.drawRect(X+2*columnWidth, columnHeight-h2, columnWidth, h2);
graphics.drawRect(X+3*columnWidth, columnHeight-h3, columnWidth, h3);
graphics.drawRect(X+4*columnWidth, columnHeight-h4, columnWidth, h4);
graphics.drawRect(X+5*columnWidth, columnHeight-h5, columnWidth, h5);
chartGraphics.createImage("D:\\temp\\chart.jpg");
}
}
我不知道你能不能只用jdk1.1版本绘制一个饼图,不要用graphic2D等工具,