473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

picture baox and counting the black pixels..

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 :)
Nov 16 '05 #1
4 6517
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 :)

Nov 16 '05 #2
Hi serdar c,

An empty PictureBox does not contain anything you can get colors off.
There is a GetPixel(x, y) you can use on the PictureBox's Bitmap, but
if the PictureBox is empty the Image property is null.

Bitmap b = (Bitmap)PictureBox.Image;
Color c = b.GetPixel(x, y);

On Mon, 20 Dec 2004 00:49:02 -0800, serdar c <serdar
c@discussions.microsoft.com> wrote:
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 :)


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
thanks so much for helping, have a nice day :)

"Bob Powell [MVP]" wrote:
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 :)


Nov 16 '05 #4
Hi,

Bitmap bmp = new Bitmap(pictureBox1.Image, pictureBox1.Size);
Color pixelColor = picture.GetPixel(x, y);

--Liam.
"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 :)

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Maurits Veldhuyzen van Zanten | last post by:
Hello, I have a problem here, i'm try'n to make a static picture with in it a random quote. so far i have found a script that can make a pictrure from a quote, but i want the quote oppon the...
6
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run...
14
by: hamil | last post by:
I am trying to display an image in a picture box. The image is a group 4 fax black and white image of a piece of sheet music. The original resolution is 300 X 300 dpi. I want to have the picture...
4
by: Dave | last post by:
Does any one know how to compare pixels in a picture, or a dll that will allow me to do so. I need to be able to find objects in a picture. Like a table, chair, car etc. Compare a given picture say...
8
by: Lad | last post by:
Is it possible to change a picture resolution with Python? Let's say I have a picture with a resolution of 96 dpi and I would like to increase to 256dpi or higher. Thank you for your reply. LL
0
by: paruntha | last post by:
Hi, I am using Visual Basics 2005 and I am reading 8 bit values (pixel) from a CMOS camera (385 * 288 pixels) throught a serial port and need help in creating an image out of these values in BMP...
0
debasisdas
by: debasisdas | last post by:
Add two picture boxes to a form. Set the ScaleMode property of both the pictureboxes to 3-Pixels. General declaration -------------------------------- Const ubx = 1000 Const uby = 500 Dim...
8
by: Louis | last post by:
Hello, My website is 910 pixels wide. The content area is 552 pixels wide. If I place a picture in the content area that is wider than 552 pixels my site becomes wider than 910 pixels. I do not...
4
Thekid
by: Thekid | last post by:
Hi, I know I need to use PIL, but how would I count all of the red pixels in a given image? The image is simply a vertical red line on a black background. import PIL im =...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.