怎么利用JAI包实现多页TIF文件的读取和保存,主要是保存,最好还是压缩后保存.
在网上找了很多资料,都没有说到多页TIF文件的保存.
如果不是利用JAI的也可以,最好有例子.

解决方案 »

  1.   

    public class Tiff2JPEG {
      public static int DISPLAY_WIDTH = 640;
      public static boolean doTiff2JPEG (String filename, String imageDir) {
        File file = new File(imageDir + filename);
        SeekableStream s = null;
        TIFFDecodeParam param = null;
        RenderedImage op = null;
        String simplefilename = filename.substring(0,filename.lastIndexOf("."));
        RenderedOp image = null;
        try {
          s = new FileSeekableStream(file);
          ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
          int numofpages = dec.getNumPages();
          for (int i=0; i< numofpages; i++) {
            op = new NullOpImage
               (dec.decodeAsRenderedImage(i),null,null,OpImage.OP_COMPUTE_BOUND);
            image = JAI.create("stream", op);
            int width = op.getWidth();
            int height = op.getHeight();
            double conversionFactor = (double)DISPLAY_WIDTH / (double)width;
            float conversionFactor_ = DISPLAY_WIDTH / width;
            int thumbHeight = (int)((double)height * conversionFactor);
            int thumbWidth = (int)((double)width * conversionFactor);
            Dimension dim = new Dimension(thumbHeight, thumbWidth);        
            JAI.setDefaultRenderingSize(dim);
            JAI.setDefaultTileSize(dim);
            JAI.create("filestore", 
               image, imageDir + simplefilename + "." + i + ".png", "png");
          }
        } catch (IOException e) {
          System.out.println(e.getLocalizedMessage());
          return false;
        }
        return true;
      }
    }
      

  2.   

    不是要保存到其它格式
    还是要保存为多页的TIF格式的