Friday, January 31, 2014

Load and Save Image in C #



This is a post I am related to C # (C sharp). In this post, I will explain the steps of making the application of C #. Tutorial-making an application Load and Save Image is the basis of the use of the C # application-related image. The image to be processed must be opened and saved. Now it's time to direct the implementation of the program.
Starting from the simplest, though probably many of you already know very well about this one programming language, that is, how to open and save an image file of any type using C #. In my implementation using Microsoft Visual Studio.

Please read:

1.        the first step, open the C # program and create a new file by choosing File > > New Project (Ctrl + Shift + N) > > select Windows Application, and name the file according to your needs (e.g. LoadSave) and press OK. Next would come an empty form.



2.   a Component used for this simple program is: 
           • OpenFileDialog 
           • SaveFileDialog 
           • PictureBox 
           • Button

Click and put option component of the program which will be used as the image below:


       3.  Then double click on the button "Load Image" and add the following code :

OpenFileDialog file = new OpenFileDialog();
string lokasi = file.InitialDirectory;
lokasi = @"C:\Users\ardha\Desktop";
file.Title = "Open Image File";
file.Filter = "Image Files(*.jpg,*.png,*.tiff,*.bmp,*.gif)|*.jpg;*.png;*.tiff;*.bmp;*.gif";
file.FilterIndex = 2;
file.RestoreDirectory = true;
if (file.ShowDialog() == DialogResult.OK)
                     {
                     pictureBox1.Image = new Bitmap(file.FileName);
                                     }


The purpose of the Load Image button to select an image file is what you want to display in the picture box. The desired file types can be specified via the syntax Filter (in the above example file.Filter), whereas if you want to directly refer to a particular directory can be used syntax InitialDirectory (in the above example file.InitialDirectory)
4. as for the save image file, double click on the button "Save Image" and add the following code :
 
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.InitialDirectory = @"C:\Users\ardha\Desktop";
            saveFile.Filter = "Image      
            Files(*.jpg,*.png,*.tiff,*.bmp,*.gif)|*.jpg;*.png;*.tiff;*.bmp;*.gif";
            saveFile.Title = "Save an image";
            saveFile.AddExtension = true;
            saveFile.DefaultExt = "bmp";
            saveFile.FilterIndex = 2;
            saveFile.RestoreDirectory = true;

            if (saveFile.ShowDialog() == DialogResult.OK)
                {
                string fName = saveFile.FileName;
                pictureBox1.Image.Save(fName, ImageFormat.Bmp)
                }

5. the application was complete, after adding the source code above, lives in the run course. And the results were as follows:



For more details on this please download program understanding program files and full-length project
download program files binary here
download full project here
download the exe only here
download the document here
download picture here
for more information contact on ardhamail@gmail.com

Guide to download: click the download link above, after provided it would appear adf.ly page, wait a few seconds until "appears on the top right corner of the ad skip writing. Click the button, the page will appear after that ziddu, please click on the download button that appears on the page ziddu
NB: in this tutorial ditulisa program using the Visual studio IDE. with the target framework > 4.0. So at a minimum your computer must be installed or windows vista or windows xp with the .NET framework 4.0 to be able to run programs *. exe, while for open the project inevitably must install microsoft visual studio 2012

 



3 comments: