The image displayed in a PictureBox can be examined using the
Bitmap.GetPixel(x,y) method.
If the PictureBox is empty then it's a bit difficult to look at the contents
of the screen.
Given that you have a valid imagein the picturebox you can use something
like this to count the black pixels.
Bitmap myImage=(whatever image is in the picturebox)
int count=0;
for(int y=0; y<myimage.Height; y++)
{
for(int x=0; x<myimage.Width; x++)
{
Color c=myimage.GetPixel(x,y);
if(c.R==0 && c.G==0 && c.B==0)
count++;
}
}
The count now contains the number of black pixels.
Hope this helps.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"serdar c" <serdar
c@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
hi everyone, i am writing a program for my scool project and i need to
count the number of black pixels in a white empty picture box.. in the old
visual basic there was a really simple command called "Pset(x,y)" retruns the
color code of the specified location. but i couldnt found much things that does
the same thing in c sharp.. please tell me if u know anything abt this.. i
tried to use gdi but couldnt understand how does it works too much.. thanx for
spending you time on reading my question and for ur help :)