Making Image editing tool in C#

Image Edditor in C#
Image Edditor in C#
ImageEditorInCSharp.zip
20.5 KiB
747 Downloads
Details

In this article we will learn to make a image editing tool with the help of C#. In this image editing tool we include re-sizing image, cropping image,brightness and contrast in images,rotation and other various common image editing functionality.

first we learn that how to implement these functionality in image one by one. so first we need to learn that how to show an image in windows form? for this we can take a picturebox control, picturebox control able to load an image file format like bmp, jpeg, gif,tiff file also.

So let start with our first step.

Start a new windows application and add one splitcontainer, picturebox, menustrip, toolstrip on windows form. Arrange controls on the form like this.

  Image editor in C#

Now we need to open image on the form so we use open filedialog class for selecting image file.

 Code :

  Private Img As Image
  1. Declare Img as object of Image class. Image class is the member of System.Drawing namespace, it is abstrat base class that provides functionality for raster images(bitmaps) and vector images(Metafile) descended classes.
  2.  
  3. Use openfiledialog on OpenToolStripMenuItem_Click event
  4. <pre lang="csharp">   private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
  5.         {
  6.             OpenFileDialog Dlg = new OpenFileDialog();
  7.             Dlg.Filter = "";
  8.             Dlg.Title = "Select image";
  9.             if (Dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  10.             {
  11.                 Img = Image.FromFile(Dlg.FileName);
  12.                 //Image.FromFile(String) method creates an image from the specifed file, here dlg.Filename contains the name of the file from which to create the image
  13.                 LoadImage();
  14.             }
  15.          }
  1.  private void LoadImage()
  2.         {
  3.             //we set the picturebox size according to image, we can get image width and height with the help of Image.Width and Image.height properties.
  4.           
  5.             int imgWidth = Img.Width;
  6.             int imghieght = Img.Height;
  7.             PictureBox1.Width = imgWidth;
  8.             PictureBox1.Height = imghieght;
  9.             PictureBox1.Image = Img;
  10.             PictureBoxLocation();
  11.  
  12.             OriginalImageSize = new Size(imgWidth, imghieght);
  13.             SetResizeInfo();
  14.         }

    Suppose that your picturebox or image size is smaller than background panel than image will show in the corner of the panel in upperside and this is not professional look of tool so we set the picturebox or image location on panel.

After doing this image will always show in center of panel

  1.   private void PictureBoxLocation()
  2.         {
  3.             int _x = 0;
  4.             int _y = 0;
  5.  
  6.             if (SplitContainer1.Panel1.Width &gt; PictureBox1.Width)
  7.             {
  8.                 _x = (SplitContainer1.Panel1.Width - PictureBox1.Width) / 2;
  9.             }
  10.  
  11.             if (SplitContainer1.Panel1.Height &gt; PictureBox1.Height)
  12.             {
  13.                 _y = (SplitContainer1.Panel1.Height - PictureBox1.Height) / 2;
  14.             }
  15.  
  16.             PictureBox1.Location = new Point(_x, _y);
  17.         }
  1.  private void SplitContainer1_Panel1_Resize(object sender, EventArgs e)
  2.         {
  3.             PictureBoxLocation();
  4.         }

Making Image editing tool in C# - 2

 You can try this code  for making image editing tool,in this article you learn that how to show image on form, in next article of this series describe to Resize image….thanks


Other related articles of this series:

making image editing tool in C#- Resize an image

Making image editing tool in C#- Crop an image

Making image editing tool in C#- Brightness of an image

Making image editing tool in C#- Rotations of an image


facebooktwittergoogle_plusredditpinterestlinkedinmail
  • northern flicker

    thank you for your write-up,My issue has been resolvedthat was related to open image .