日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

将单页/多页 tif转换 jpg 格式方法和所需jar包

發布時間:2023/12/8 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 将单页/多页 tif转换 jpg 格式方法和所需jar包 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

所需jar包:
鏈接:https://pan.baidu.com/s/1GBBWEiBCHy5y3TbKhkTOfg
提取碼:mfvs
將 tif 轉換 jpg 格式(單頁tif)

public static String tiffTuanJPG(String filePath) {String format = filePath.substring(filePath.lastIndexOf(".") + 1);String turnJpgFile = filePath.replace("tif", "jpg");if (format.equals("tif")) {File fileTif = new File(turnJpgFile);if (fileTif.exists()) {System.out.println("該tif文件已經轉換為 JPG 文件:" + turnJpgFile);return turnJpgFile;}//讀取iff文件RenderedOp rd = JAI.create("fileload", filePath);OutputStream ops = null;try {ops = new FileOutputStream(turnJpgFile);//文件存儲輸出流JPEGEncodeParam param = new JPEGEncodeParam();//指定輸出格式ImageEncoder image = ImageCodec.createImageEncoder("JPEG", ops, param);image.encode(rd);//解析輸出流進行輸出ops.close();System.out.println("tif轉換jpg成功:" + filePath);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}return turnJpgFile; }

將 tif 轉換 jpg 格式(多頁tif)
參考:https://www.cnblogs.com/101key/p/3324601.html

public void tif2Jpg(String fileAbsolutePath) {if (fileAbsolutePath == null || "".equals(fileAbsolutePath.trim())){return ;}if (!new File(fileAbsolutePath).exists()){logger.info("系統找不到指定文件【"+fileAbsolutePath+"】");return ;}FileSeekableStream fileSeekStream = null;try {fileSeekStream = new FileSeekableStream(fileAbsolutePath);TIFFEncodeParam tiffEncodeParam = new TIFFEncodeParam();JPEGEncodeParam jpegEncodeParam = new JPEGEncodeParam();ImageDecoder dec = ImageCodec.createImageDecoder("tiff", fileSeekStream, null);int count = dec.getNumPages();tiffEncodeParam.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);tiffEncodeParam.setLittleEndian(false);logger.info("該tif文件共有【" + count + "】頁");String filePathPrefix = fileAbsolutePath.substring(0, fileAbsolutePath.lastIndexOf("."));for (int i = 0; i < count; i++) {RenderedImage renderedImage = dec.decodeAsRenderedImage(i);File imgFile = new File(filePathPrefix + "_" + i + ".jpg");logger.info("每頁分別保存至: " + imgFile.getCanonicalPath());ParameterBlock pb = new ParameterBlock();pb.addSource(renderedImage);pb.add(imgFile.toString());pb.add("JPEG");pb.add(jpegEncodeParam);RenderedOp renderedOp = JAI.create("filestore",pb);renderedOp.dispose();}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {if (fileSeekStream != null){try {fileSeekStream.close();} catch (IOException e) {}fileSeekStream = null;}}} @Testpublic void test() {String fileName = "D:\\home\\oldZJYX\\7a400398f2db482baec96e4f4d9e68a9\\揚州中行8269-201904.tif";String s = tiffTuanJPG(fileName);System.out.println(s);}

總結

以上是生活随笔為你收集整理的将单页/多页 tif转换 jpg 格式方法和所需jar包的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。