c#中怎样把tif图片格式转化成bmp格式,求代码!
1个回答
展开全部
private void jpgToolStripMenuItem_Click(object sender, EventArgs e)
{
Gdal.AllRegister();
Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
string filePathName = "";
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
\\filename保存了路径加文件名
filePathName = dlg.FileName;
}
if (filePathName == "")
{
MessageBox.Show("影像路径不能为空");
return;
}
Dataset ds = Gdal.Open(filePathName, Access.GA_ReadOnly);
Driver drv = ds.GetDriver();
if (drv == null)
{
MessageBox.Show("Can't get driver!");
System.Environment.Exit(-1);
}
string strSavePathName = @"E:\TEMP\TifToJpg\myJpg1.jpg";
drv.CreateCopy(strSavePathName,ds,0,null,null,null); \\tif转换成jpg
drv.CreateCopy(@"E:\TEMP\TifToJpg\myBmp1.bmp", ds, 0, null, null, null);\\tif转换成bmp
drv.CreateCopy(@"E:\TEMP\TifToJpg\myPng1.png", ds, 0, null, null, null);\\tif转换成png
drv.CreateCopy(@"E:\TEMP\TifToJpg\myGif1.gif", ds, 0, null, null, null);\\tif转换成gif
MessageBox.Show("另存成功!");
}
{
Gdal.AllRegister();
Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
string filePathName = "";
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
\\filename保存了路径加文件名
filePathName = dlg.FileName;
}
if (filePathName == "")
{
MessageBox.Show("影像路径不能为空");
return;
}
Dataset ds = Gdal.Open(filePathName, Access.GA_ReadOnly);
Driver drv = ds.GetDriver();
if (drv == null)
{
MessageBox.Show("Can't get driver!");
System.Environment.Exit(-1);
}
string strSavePathName = @"E:\TEMP\TifToJpg\myJpg1.jpg";
drv.CreateCopy(strSavePathName,ds,0,null,null,null); \\tif转换成jpg
drv.CreateCopy(@"E:\TEMP\TifToJpg\myBmp1.bmp", ds, 0, null, null, null);\\tif转换成bmp
drv.CreateCopy(@"E:\TEMP\TifToJpg\myPng1.png", ds, 0, null, null, null);\\tif转换成png
drv.CreateCopy(@"E:\TEMP\TifToJpg\myGif1.gif", ds, 0, null, null, null);\\tif转换成gif
MessageBox.Show("另存成功!");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |