JAVA保存图片的问题 请问JAVA怎么把内存里的Image保存到磁盘上?gif或者image格式都可以,请高手指教,最好有演示代码,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void Create(){ Buffer buf = null;//设置为内存中的数据 BufferToImage btoi = null; Image img = null; btoi = new BufferToImage((VideoFormat) buf.getFormat()); img = btoi.createImage(buf); ; String file = JOptionPane.showInputDialog(this, "input the flel name you want to store"); BufferedImage bi = (BufferedImage) createImage(200, 200); File f=new File("media/"+file+".jpg") ; FileOutputStream out = null; try { out =new FileOutputStream(f); } catch (java.io.FileNotFoundException io) { System.out.println("File Not Found"); } JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi); param.setQuality(1f, false); encoder.setJPEGEncodeParam(param); try { encoder.encode(bi); out.close(); } catch (java.io.IOException io) { System.out.println("IOException"); } } 谢谢,请问里面用到的BufferToImage,VideoFormat这两个类是哪个包里的?还是自己写的? BufferToImage,VideoFormat是Java Media Framework里面的东东。楼主可以到百度上找找这方面的文章看看 高手请帮忙 求一个抽签算法 问一个很简单的问题.急!!! 关于等差数列和的问题 各位熟悉JMF, RTP传输的高手请进 - 高分求教 怎样解决JFileChooser在屏幕上停留的问题 请求帮助 TreeMap和HashMap的区别 连db2的url怎么写哦.... 哪里可以下载IBM提供的JNDI的服务程序? Exception in thread "main" 免费申请6位QQ号 SQL2000如何跟 JBuilder 连接?
Buffer buf = null;//设置为内存中的数据
BufferToImage btoi = null;
Image img = null;
btoi = new BufferToImage((VideoFormat) buf.getFormat());
img = btoi.createImage(buf);
; String file = JOptionPane.showInputDialog(this,
"input the flel name you want to store");
BufferedImage bi = (BufferedImage) createImage(200, 200);
File f=new File("media/"+file+".jpg") ;
FileOutputStream out = null;
try {
out =new FileOutputStream(f);
} catch (java.io.FileNotFoundException io) {
System.out.println("File Not Found");
} JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false);
encoder.setJPEGEncodeParam(param);
try {
encoder.encode(bi);
out.close();
} catch (java.io.IOException io) {
System.out.println("IOException");
} }