JAVA调用GDAL实现影像格式转换,以tif to jpg为例
前言
本文简单实现java调用GDAL实现影像格式转换。
package Marcus.com;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.Driver;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
public class tif2jpg {
public static void main(String[] args) {
// TODO Auto-generated method stub
String INPUT_PATH="D:/airplane20.tif";
String OUTPUT_PATH="D:/airplane20.jpg";
//注册GDAL
gdal.AllRegister();
//设置中文
gdal.SetConfigOption("gdal_FILENAME_IS_UTF8", "YES");
//只读方式读取数据
Dataset ds=gdal.Open(INPUT_PATH,gdalconstConstants.GA_ReadOnly);
//判断数据源是否非空
if (ds==null)
{
System.err.println("GDALOpen failed-"+gdal.GetLastErrorNo());
System.err.println(gdal.GetLastErrorMsg());
System.exit(1);
}
Driver hDriver=ds.GetDriver();
System.out.println("Driver: "+hDriver.getShortName()+"/"+hDriver.getLongName());
hDriver.CreateCopy(OUTPUT_PATH, ds);
ds.delete();
hDriver.delete();
System.out.println("Suscess!");
}
}
转载自:https://blog.csdn.net/Allen__Iverson/article/details/74929690