Click here to Skip to main content
Click here to Skip to main content

Cropping Tool

By , 22 Apr 2013
Rate this:
Please Sign up or sign in to vote.

Introduction

This simple project I have made to help the data entry operators in various offices who need to crop a photo from an scanned form and extract out signature from the form. To do these peoples use the big package of adobe or some other packages what are relatively bigger. To made the task simple I have made this cropping tool, Hope this will made the operators easily done the cropping task. The idea came to my mind when my 4 years nephew trying to crop her image from a group photo, She don't know to use Photoshop, she use to forgot the steps. Later I have improve this a bit ore to help data entry operators of my office.

Background

In this article I have done the cropping task on mouse event. So I hope This part of coding can be used in other project also if anyone wants to crop an image for some other project. In the signature section of the WinForm, I have made an option to de-color the background of the image, such as if the background color of a form is not white One can erase the background color to black and white. I have use this part of the coding in many of my image processing project.

Using the code  

The code of this project can be implement in various other project. The following part is used to erase the background color of the image what will made the signature clean from other backcolors.

try
{
    Bitmap img = new Bitmap(pictureBox3.Image);
    Color c;
    for (int i = 0; i < img.Width; i++)
    {
        for (int j = 0; j < img.Height; j++)
        {
            c = img.GetPixel(i, j);
            int r = 0;
            r = Convert.ToInt16(c.R);
            int g = 0;
            g = Convert.ToInt16(c.G);
            int b = 0;
            b = Convert.ToInt16(c.B);
            int ans = (r + g + b) / 3;
            if (ans > 128)
            {
                r = 255;
                g = 255;
                b = 255;
            }
            else
            {
                r = 0;
                g = 0;
                b = 0;
            }
            c = Color.FromArgb(r, g, b);
            img.SetPixel(i, j, c);
        }
    }
    pictureBox3.Image = img;
    MessageBox.Show("SUCESSFULLY DONE");

}
catch (Exception ex) { MessageBox.Show(ex.Message); } 

Points of Interest

This is a simple cropping tool. I hope this will help one to develop image processing project in C#. Code behind a Picturebox and code to handle color inside Picturebox can be learned from it what is most important part all image processing software in C#.

History

I am developing it to more better quality and more other features will be added to it in next module. If this part really help people, This will an encourage to me as this is my first article here in CodeProject.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

assamheart

United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 22 Apr 2013
Article Copyright 2013 by assamheart
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid