代码如下,很简单
try {
//tiff图片的位置
String tiffPath = "C:\Users\LENOVO\Desktop\SG\aaa.tif";
//这个是要转为PNG的目标文件,不用创建会自动创建
String pngFilePath = "C:\Users\LENOVO\Desktop\SG\result.png";
BufferedImage bufImage = ImageIO.read(new File(tiffPath));
//可以是jpg等其它图片格式
ImageIO.write(bufImage, "png", new File(pngFilePath));
bufferegImage.flush();
} catch (IOException e) {
e.printStackTrace();
}
代码简单,就两句,接下来的JAR包导入才是重点!!!!!
相关的jar包找了很久找不到,最后在这个仓库才能下载,下面这个配置是放在pom文件中的,就是临时作为下载的仓库,如果要使用这个方式,maven仓库的setting.xml仓库配置的URL这个mirrorOf标签不能为*,否则下面这个配置就不生效,依旧会从你maven配置的仓库去下载,切记!!!!
GeoSolutions http://maven.geo-solutions.it/
以上配置完成后,需要再pom文件中引入以下几个坐标:
it.geosolutions.imageio-ext imageio-ext-utilities 1.3.2 it.geosolutions.imageio-ext imageio-ext-cog-commons 1.3.3 it.geosolutions.imageio-ext imageio-ext-geocore 1.1.13
然后等他下载完成即可。
后面补一句:这几个jar包的坐标是真特么难找



