import javax.imageio.*;//jdk1.4后才支持
存图片:
BufferedImage bi;
File file = new File (currentFileName);
String format = "JPEG";
ImageIO.write(bi,format,file);//将图片保存为jpeg格式的文件file。也可以保存为jpg格式
读图片:
File file = new File(fileName);
BufferedImage image = ImageIO.read(file);//打开名为file的图片,只可以打开jpg和gif的

解决方案 »

  1.   

    保存gif的也一样啊
    String format = "GIF";
    //String format = "JPEG";
    ImageIO.write(bi,format,file)
    就按照他的程序改就是了
      

  2.   

    楼主用的是jdk1.4吗?!1.4之前这个问题比较麻烦,只支持读取功能,而根本不支持写入,想写入图形的话,要下一个
      

  3.   

    GIF编码器,使用它里头的com.sun.image.codec.jpeg,他能够将图形保存为JPEG格式,但我没有使用过^_^
      

  4.   

    java不支持bmp格式。
    如果保存为jpeg格式,给你一个例子。
      private 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) {
          e.printStackTrace();
        }
      }