将图片转换为另一种格式的图像时需要使用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信息提示);
}
}