Calculate total pixels in an image
can somebody tell me how to calculate total number of pixels in an image using c#
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
hend khalid2 reputationPosted Sep 19, 2013, 5:38 PM EDT
saifullah khanRank #4,887 · 320 reputationPosted Feb 12, 2012, 9:00 PM EST
Bitmap image1; int count; private void Button1_Click(System.Object sender, System.EventArgs e) { try { // Retrieve the image. image1 = new Bitmap(@"C:\Documents and Settings\All Users\" + @"Documents\My Music\music.bmp", true); int x, y; // Loop through the images pixels to reset color. for(x=0; x { for(y=0; y { Color pixelColor = image1.GetPixel(x, y); ++count; } } // Set the PictureBox to display the image. PictureBox1.Image = image1; // Display the pixel format in Label1. label1.Text = "Pixel format: "+count; } catch(ArgumentException) { MessageBox.Show("There was an error." + "Check the path to the image file."); } }