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东西,保留为方便查询与使用。
- import java.io.File;
- import java.io.IOException;
- import com.sun.media.jai.codec.FileSeekableStream;
- import com.sun.media.jai.codec.ImageCodec;
- import com.sun.media.jai.codec.ImageDecoder;
- import com.sun.media.jai.codec.SeekableStream;
- import com.sun.media.jai.codec.TIFFDecodeParam;
- import com.sun.media.jai.codec.TIFFDirectory;
- public class TifTest {
- public static void readTifFIle(String fileName) {
- File file = new File(fileName);
- SeekableStream s = null;
- TIFFDecodeParam param = null;
- try {
- s = new FileSeekableStream(file);
- ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
- int numofpages;
- numofpages = dec.getNumPages();
- System.out.print(numofpages);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- //读取文件的 页数
- public static void readTifFIle2(String fileName){
- File file = new File(fileName);
- SeekableStream s = null;
- try {
- s = new FileSeekableStream(file);
- System.out.println(TIFFDirectory.getNumDirectories(s));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- String fileName = "C:\\婚姻证明.tif";
- readTifFIle2(fileName);
- }
- /* public static int DISPLAY_WIDTH = 300;
- 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("."));
- try {
- s = new FileSeekableStream(file);
- ImageDecoder dec = (ImageDecoder) 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);
- int width = op.getWidth();
- int height = op.getHeight();
- double conversionFactor = (double)DISPLAY_WIDTH / (double)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",
- op, imageDir <i>File.separator</i> simplefilename + "." + i + ".jpg", "png");
- }
- } catch (IOException e) {
- System.out.println(e.getLocalizedMessage());
- return false;
- }
- return true;
- }
- public static void main(String[] args) {
- TifTest.doTiff2JPEG("aa.tiff", "d:temp");
- }*/
- }