Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Namespace ex13_06
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private system. Drawing. Bitmap mybitmap;
// Open the image to be changed (convert format.
Private void button#click (Object sender, eventargs E)
{
// Open the image file
Openfiledialog = new openfiledialog ();
Openfiledialog. filter = "image files (JPEG, GIF, BMP, etc .) | *. JPG ;*. JPEG ;*. GIF ;*. BMP ;*. TIF ;*. tiff ;*. PNG | JPEG image file (*. JPG ;*. JPEG) | *. JPG ;*. JPEG | GIF image file (*. GIF) | *. GIF | BMP image file (*. BMP) | *. BMP | TIFF image file (*. TIF ;*. tiff) | *. TIF ;*. tiff | PNG Image File (*. PNG) | *. PNG | all files (*. *) | *. *";
If (openfiledialog. showdialog () = dialogresult. OK)
{
// Obtain the original size image
Bitmap srcbitmap = new Bitmap (openfiledialog. filename );
// Obtain the scaled image and determine the image size based on the picturebox size ..
Mybitmap = new Bitmap (srcbitmap, this. picturebox1.width, this. picturebox1.height );
This. picturebox1.image = mybitmap;
}
}
// You can specify the format as needed.
Private void button2_click (Object sender, eventargs E)
{
// Convert image files
If (mybitmap = NULL)
{
MessageBox. Show ("select an image first! "," Information prompt ");
Return;
}
Savefiledialog savedlg = new savefiledialog ();
If (savedlg. showdialog () = dialogresult. Cancel)
Return;
String filename = savedlg. filename;
Try
{
If (this. combox1. selectedindex = 0)
{
// Use the. Save method of the bitmap class to store the changed image ....
// The advantage is that the image can be stored after any processing ....
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, "message prompt ");
}
}
private void form1_load (Object sender, eventargs e)
{< br> This. combobox1.selectedindex = 0;
}< BR >}