When you
Convert a picture to an image in another format, you need to use the ImageFormat class, which is used primarily to specify the format of the image. The code is as follows:
private void Button2_Click (object sender, EventArgs e)
{
//Convert image file
if (Mybitmap = = null)
{
MessageBox.Show ("Please select an image first!") "," Information Tips ");
return;
}
SaveFileDialog Savedlg = new SaveFileDialog ();
if (savedlg.showdialog () = = DialogResult.Cancel)
return;
string fileName = Savedlg.filename;
Try
{
if (this.combobox1). SelectedIndex ==0)
{
Mybitmap.save (fileName +. bmp, SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.BMP); }
if (This.comboBox1.SelectedIndex ==1)
{
Mybitmap.save (fileName +. jpg), SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.GIF);
}
if (This.comboBox1.SelectedIndex = = 2)
{
Mybitmap.save (fileName +. png) ", System.Drawing.Imaging.ImageFormat.Jpeg);
}
if (This.comboBox1.SelectedIndex = = 3)
{
Mybitmap.save (fileName +. gif) , SysteM.drawing.imaging.imageformat.png);
}
if (This.comboBox1.SelectedIndex = = 4)
{
Mybitmap.save (fileName +. tif) ", System.Drawing.Imaging.ImageFormat.Tiff);
}
if (This.comboBox1.SelectedIndex = = 5)
{
Mybitmap.save (FileName +. wmf) ", SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.WMF);
}
}
catch (Exception ex)
{
MessageBox.Show (ex. message, "information hint");
}
}