Java实现tif/tiff/bmp图片转换png图片

package org.analysisitem20181016.test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageEncoder;
import com.sun.media.jai.codec.PNGEncodeParam;

public class Test2019112802 {

    public static void main(String[] args) {
        try {
            test();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void test() throws Exception {
        //tif/tiff/bmp转换png格式
//        String tiffFilePath = "d:/test/20191129.tif";
//        String tiffFilePath = "d:/test/20191129.bmp";
        String tiffFilePath = "d:/test/20191129.webp";
        String pngFilePath = "d:/test/20191129_3.png";
        RenderedOp ro = JAI.create("fileload", tiffFilePath);
        OutputStream os = new FileOutputStream(pngFilePath);
        PNGEncodeParam param = new PNGEncodeParam.RGB();
        ImageEncoder ie = ImageCodec.createImageEncoder("PNG", os, param);
        ie.encode(ro);
        os.flush();
        os.close();
        System.out.println("图片转换成功!");
    }

}

 

posted @ 2019-12-02 09:25  ラピスラズリ(Dawn)  阅读(2051)  评论(0编辑  收藏  举报