Picture Box, pixel color pickup

harry_uk

New member
Joined
Dec 17, 2006
Messages
4
Programming Experience
Beginner
Hi everybody. Im working on a project in which, i need to find out the color of a pixel in a image which is inside a picturebox. (ie Picturebox.Image). This i dont need to find using x,y of mouse points. But given a pixel location I need to get the color of the point.

Also my pictures wont be too big. They are only thumbnails. So memory resources is not a problem for me at all.

To summarise I need to know

1) What is the color of a particular pixel of picturebox

2) How to find the location of the particular pixel, since im not using mouse, i cannot use x,y.

Im not very advanced in .net and i donno anything abt image programming. I was reading a lot of posts here, from which i gained a nice idea of what i need to do.

Any help will really be appreciated and very useful to me.

Thanks in advance.
 
You mean user is supposed to type in the x and y coordinates by keyboard?
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] thecolor [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Color = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](PictureBox1.Image, Bitmap).GetPixel(x, y)
[/SIZE]
 
Frankly, i donno how to arrive at a location.

Should i input x,y or there is someother way to get the co-ordinates inside the image?

Definitely the mouse cannot be used, they dont use a mouse at all, i mean the clients... lol

And that bmp.getpixel, i suppose i have to declare

dim bmp as new Bitmap right?

How am i to reference this bmp to my picturebox?

Some sample code would really help me a lot, thanks john.
 
So, what input device are to be used? Usually other visual pointer devices like pens or touchsceen use the same events as mouse for screen navigation. Else if this is some special keyboard-only usage you have to create your own navigation system. This could be as simple as defining a starting point (0,0) and use the keyboard events to detect the arrow keys, in which case you add/subtract to the x/y axis. You also then have to use the picturebox paint event and draw some visual marker at the current point location since there is no mouse cursor to see.

Bitmap class is derived from Image class, so I adapted the previous code example to use the picturebox.image and cast it to bitmap.
 
Wow, thanks for stating that its part of picturebox.image.bitmap...

That could be very useful for me.

As far as inputs are concerned, I just need to know the color of a particular position and match it whether it has predefined set of colors in those pixels i specify. Only for this purpose i need to know the co-ordinates. Infact it is the same set of co-ordinates of pixels and colors i need to check in all the images. The whole process is gonna be automated with all the thumbnail images.

Hence i dont have to input through mouse/keyboard. Maybe when i program, to find out what that those co-ordinates are i need a mouse, but after i am done locating i dont need a mouse at all.

Dim thecolor As Color = DirectCast(PictureBox1.Image, Bitmap).GetPixel(x, y)

In this code u gave me can i just check like, suppose my image size is 50 pixels * 50 pixels, can i just feed in value getpixel(25,25)to get the color of the pixel in that location(25,25) inside the image, or this x,y refers to where the mouse pointer is situated. In case there is no mouse pointer, can't i program at all.

I mean in all the images i only need to check colors in 25,25 and 25,26 and 25,27, and find out whether the pixel is black there, can i just feed
these values in your code, i mean in x,y.

Thanks for all your help john!!
 
x/y is image coordinates, zero based for image width/height in pixel dimensions.
 
Back
Top