將圖片轉換為另一種格式的圖像時需要使用ImageFormat類該類主要用來指定圖像的格式代碼如下
privatevoidbutton_Click(objectsenderEventArgse)
{
//轉換圖像文件
if(MyBitmap==null)
{
MessageBoxShow(請首先選擇一幅圖像!信息提示);
return;
}
SaveFileDialogsaveDlg=newSaveFileDialog();
if(saveDlgShowDialog()==DialogResultCancel)
return;
stringfileName=saveDlgFileName;
try
{
if(boBoxSelectedIndex==)
{
MyBitmapSave(fileName+bmpSystemDrawingImagingImageFormatBmp);
}
if(boBoxSelectedIndex==)
{
MyBitmapSave(fileName+jpgSystemDrawingImagingImageFormatGif);
}
if(boBoxSelectedIndex==)
{
MyBitmapSave(fileName+pngSystemDrawingImagingImageFormatJpeg);
}
if(boBoxSelectedIndex==)
{
MyBitmapSave(fileName+gifSystemDrawingImagingImageFormatPng);
}
if(boBoxSelectedIndex==)
{
MyBitmapSave(fileName+tifSystemDrawingImagingImageFormatTiff);
}
if(boBoxSelectedIndex==)
{
MyBitmapSave(fileName+wmfSystemDrawingImagingImageFormatWmf);
}
}
catch(Exceptionex)
{
MessageBoxShow(exMessage信息提示);
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11428.html