Java 不保存图片,在浏览器中显示图片

yjj3844 2011-06-28 03:28:10
如题,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);
}
}
这张图片是我自己画的,我想让它在浏览器中显示,该如何做呢?
...全文
241 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinyuyefei 2011-07-04
  • 打赏
  • 举报
回复
楼主自问自答 能不能把结果发出来 让大家看下 扫扫盲?
yjj3844 2011-07-01
  • 打赏
  • 举报
回复
呵呵 已经解决了 不过还是要谢谢你!
飞跃颠峰 2011-06-29
  • 打赏
  • 举报
回复
不行吧,你不能控制浏览器的行为,只能把资源名称路径交给它
都不保存,浏览器去哪取呢
yjj3844 2011-06-29
  • 打赏
  • 举报
回复
没有人回复吗?
看来我自己顶了!

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧