请问JAVA怎么把内存里的Image保存到磁盘上?gif或者image格式都可以,请高手指教,最好有演示代码,谢谢

解决方案 »

  1.   

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

  2.   

    谢谢,请问里面用到的BufferToImage,VideoFormat这两个类是哪个包里的?还是自己写的?
      

  3.   

    BufferToImage,VideoFormat是Java Media Framework里面的东东。楼主可以到百度上找找这方面的文章看看