Java 不保存图片,在浏览器中显示图片
如题,public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int width = 25, height = 30;
TestImage jg = new TestImage();
jg.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = jg.image.getGraphics();
// 画坐标
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
g.setColor(Color.BLACK);
g.drawString("3", 8, 13);
g.drawString("--",8, 18);
g.drawString("4", 8, 25);
jg.createJpg("d:\\aaa.jpg");
System.out.println("生成成功!");
}
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);
}
}
这张图片是我自己画的,我想让它在浏览器中显示,该如何做呢?