Java jai 读取tif页数

ar包下载:

http://dl.iteye.com/topics/download/d3759fda-23a4-3799-a667-e406b38cb87e

http://dl.iteye.com/topics/download/32a9981c-8e9d-3ad8-87eb-68cb9f08ade3

参考:http://zhanghongliang-cyj.iteye.com/blog/1130456

用的sun的jai东西,保留为方便查询与使用。

Java代码   收藏代码
  1.    
  2.   
  3. import java.io.File;  
  4. import java.io.IOException;  
  5.   
  6. import com.sun.media.jai.codec.FileSeekableStream;  
  7. import com.sun.media.jai.codec.ImageCodec;  
  8. import com.sun.media.jai.codec.ImageDecoder;  
  9. import com.sun.media.jai.codec.SeekableStream;  
  10. import com.sun.media.jai.codec.TIFFDecodeParam;  
  11. import com.sun.media.jai.codec.TIFFDirectory;  
  12.   
  13. public class TifTest {  
  14.     public static void readTifFIle(String fileName) {  
  15.         File file = new File(fileName);  
  16.         SeekableStream s = null;  
  17.         TIFFDecodeParam param = null;  
  18.         try {  
  19.             s = new FileSeekableStream(file);  
  20.             ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);  
  21.             int numofpages;  
  22.             numofpages = dec.getNumPages();  
  23.             System.out.print(numofpages);  
  24.         } catch (IOException e1) {  
  25.             e1.printStackTrace();  
  26.         }  
  27.     }  
  28.     //读取文件的 页数  
  29.     public static void readTifFIle2(String fileName){  
  30.         File file = new File(fileName);  
  31.         SeekableStream s = null;  
  32.         try {  
  33.             s = new FileSeekableStream(file);  
  34.             System.out.println(TIFFDirectory.getNumDirectories(s));  
  35.         } catch (IOException e) {  
  36.             e.printStackTrace();  
  37.         }  
  38.     }  
  39.       
  40.     public static void main(String[] args) {  
  41.         String fileName = "C:\\婚姻证明.tif";  
  42.         readTifFIle2(fileName);  
  43.     }  
  44.       
  45. /*  public static int DISPLAY_WIDTH = 300; 
  46.  
  47.     public static boolean doTiff2JPEG (String filename, String imageDir) { 
  48.         File file = new File(imageDir , filename); 
  49.         SeekableStream s = null; 
  50.         TIFFDecodeParam param = null; 
  51.         RenderedImage op = null; 
  52.         String simplefilename = filename.substring(0,filename.lastIndexOf(".")); 
  53. try { 
  54.           s = new FileSeekableStream(file); 
  55.           ImageDecoder dec = (ImageDecoder) ImageCodec.createImageDecoder("tiff", s, param); 
  56. int numofpages = dec.getNumPages(); 
  57. for (int i=0; i < numofpages; i++) { 
  58.             op = new NullOpImage 
  59.                (dec.decodeAsRenderedImage(i),null,null,OpImage.OP_COMPUTE_BOUND); 
  60. int width = op.getWidth(); 
  61. int height = op.getHeight(); 
  62. double conversionFactor = (double)DISPLAY_WIDTH / (double)width; 
  63. int thumbHeight = (int)((double)height * conversionFactor); 
  64. int thumbWidth = (int)((double)width * conversionFactor); 
  65.             Dimension dim = new Dimension(thumbHeight, thumbWidth);        
  66.             JAI.setDefaultRenderingSize(dim); 
  67.             JAI.setDefaultTileSize(dim); 
  68.             JAI.create("filestore", 
  69.                     op, imageDir <i>File.separator</i> simplefilename + "." + i + ".jpg", "png"); 
  70. } 
  71. } catch (IOException e) { 
  72.           System.out.println(e.getLocalizedMessage()); 
  73. return false; 
  74. } 
  75. return true; 
  76. } 
  77.  
  78.     public static void main(String[] args) { 
  79.         TifTest.doTiff2JPEG("aa.tiff", "d:temp"); 
  80.     }*/  
  81. }  
 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值