Wednesday, February 5, 2014

Get Pixel 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 #. Application creation Tutorial How to get the number of pixels of an image is the basis of the use of the C # application-related image. The image to be processed can be searched for the number of pixelnya. 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 the programming language one, namely how to find and get any type of a pixel image using C #. In each implementation I use Microsoft Visual Studio 2012.
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 wishes (DapatkanPixel) and press OK. Next would come an empty form.

2. a Component used for this simple program is:
• OpenFileDialog
• 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 "Get Pixels" and add the following code:


             string Hitam;
             string Putih;
             string TotalPixel;
             Hitam = "" + CountPixels(new Bitmap(pictureBox1.Image), Color.FromArgb(255,
             255, 255, 255));
             Putih = "" + CountPixels(new Bitmap(pictureBox1.Image), Color.FromArgb(255,  
             0,   0,   0));
             TotalPixel = "" + ((CountPixels(new Bitmap(pictureBox1.Image),
             Color.FromArgb(255, 255, 255, 255))) + (CountPixels(new
             Bitmap(pictureBox1.Image), Color.FromArgb(255, 0, 0, 0))));
             textBox1.Text = "Black = " + Hitam + "White = " + Putih + "Total = " +
             TotalPixel;

Here we need a declaration to "CountPixel", the code CountPixel as follows:


private int CountPixels(Bitmap bm, Color target_color)
        {
            // Loop through the pixels.
            int matches = 0;
            for (int y = 0; y < bm.Height; y++)
            {
                for (int x = 0; x < bm.Width; x++)
                {
                    if (bm.GetPixel(x, y) == target_color) matches++;
                }
            }
            return matches;
        }


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 picture here
download the document here
for more information contact on ardhamail@gmail.com

Guide to download: click on the download link above, after disediaan 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 projectnya inevitably must install microsoft visual studio 2012

1 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in C SHARP, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on C SHARP. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/




    ReplyDelete