I want to write a code in c#. I want to read the pixel of an Image.
I want to find out the Percentage of these colors...Any help would be appreciated
Here is my code:
myimage = new Bitmap(image Path);
pictureBox1.Image = myimage;
ht = myimage.Height;
wid = myimage.Width;
sum=ht*wid;
for (int i = 0; i < ht; ++i)
{
for (int j = 0; j < wid; ++j)
{
pixel = myimage.GetPixel(j,i);
//pixelColorStringValue = pixel.R.ToString("D3") + " " + pixel.G.ToString("D3") + " " + pixel.B.ToString("D3");
Arrr = pixel.R;
Aggg = pixel.G;
Abbb = pixel.B;
pixelColorStringValue = Arrr + " " + Aggg + " " + Abbb.ToString();
switch (pixelColorStringValue)
{
case "255 255 255":
{
white = white + 1;
break;
}
case "000 000 000":
{
// black pixel
black = black + 1;
break;
}
}
}
}
wprs=(white / sum) * 100; `
bprs=(black / sum) * 100;
blackres.Text = wprs.ToString();
whiteres.Text = bprs.ToString();