示例: .tif图片 转.bmp
public static void main(String[] args) {
//原文件
String tifFilePath = "./defectImageTemp.tif";
//目标转换后的文件
String bmpFilePath = "./defectImageTemp.bmp";
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(tifFilePath);
os = new FileOutputStream(bmpFilePath);
BufferedImage buffImg = ImageIO.read(is);
//指定格式类型,bmp 属于 JPEG 类型
ImageIO.write(buffImg, "bmp", os);
} catch(Exception e){
e.printStackTrace();
} finally {
if(os != null){
os.flush();
os.close();
}
if (is != null){
is.close();
}
}
//这个文件流就是转换后的
FileInputStream resultIs = new FileInputStream(bmpFilePath);
}