Figure 4: changing the image format

Source: Internet
Author: User
Tags bmp image
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 >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.