473,473 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

picturebox detect pixel color

I want to detect a pixel color number when i move the mouse over de
picturebox.
I think the next line has the color but i don't now how i get it:

System.Drawing.Point pt = new Point() ;
pt.X =151;
pt.Y =195;

this.textBox3.Text =
string.Format("{0}",pictureBox1.Image.Palette.Entr ies.ToString() ) ;
this line gives the string System.Drawing.Color[]

Can some one give me a hint?

With kind regards,

Jun 26 '06 #1
3 18875
You can't read the pixels color like that. The pallete is the colors used
inside the image, not the pixels itself. Further more the image my not have
color palette at all.
The result that you get from your code is correct. The ColorPalette.Entries
property is of type array of Colors - Color[]. There is nothing more that
the ToString can return, but the name of the type.

In order to read the pixels of an image you need to create a Bitmap from
that image and then use Bitmap's GetPixel method.

To create the Bitmap you can use the constructor overload that has an Image
parameter
--
HTH
Stoitcho Goutsev (100)

"Vrijbuiter" <a_*************@hotmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com...
I want to detect a pixel color number when i move the mouse over de
picturebox.
I think the next line has the color but i don't now how i get it:

System.Drawing.Point pt = new Point() ;
pt.X =151;
pt.Y =195;

this.textBox3.Text =
string.Format("{0}",pictureBox1.Image.Palette.Entr ies.ToString() ) ;
this line gives the string System.Drawing.Color[]

Can some one give me a hint?

With kind regards,

Jun 26 '06 #2
Vrijbuiter wrote:
I want to detect a pixel color number when i move the mouse over de
picturebox.
I think the next line has the color but i don't now how i get it:

System.Drawing.Point pt = new Point() ;
pt.X =151;
pt.Y =195;

this.textBox3.Text =
string.Format("{0}",pictureBox1.Image.Palette.Entr ies.ToString() ) ;
this line gives the string System.Drawing.Color[]

Can some one give me a hint?

With kind regards,


Hi Vrijbuiter,

Give this a bash:

///
Point pt = new Point();
pt.X = 151;
pt.Y = 195;

textBox3.Text = ((pictureBox1.Image as Bitmap).GetPixel(pt.X,
pt.Y) ).ToString();
///

There's absolutely zero error handling there, so if pictureBox1.Image
doesn't correctly cast to a bitmap, you're up debug creek, without a
breakpoint.

--
Hope this helps,
Tom Spink
Jun 26 '06 #3
Goutsev and Spinks thanks for the helpfull tips.
The function .GetPixel works very well thanks a lott.

a De Vrijbuiter

Jun 27 '06 #4

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

Similar topics

3
by: Defcon31 | last post by:
hello i receive from a dll a pointer to raw image data (307200bytes grayscale values). can someone explain how i can put this image data in a picturebox in VB? or can someone post code to do it...
1
by: Dennis Myrén | last post by:
Hi. I have already posted this question once, but this repost is to ensure no gurus missed it, who might be able to help me out here; I would like to know whether it is possible - without...
1
by: Chris Auer | last post by:
I have been banging my head for a couple of hours now. No matter what I do the color that I make transparent is black. Here is the code I am using from MSDN. I have tried bitmaps, jpegs, gifs and...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
2
by: fripper | last post by:
I am using VB 2005 and want to generate a graphic in a picture box control where the color of each pixel is determined by particular values calculated for each pixel. These values are manipulated...
2
by: tlemcenvisit | last post by:
hi, I'd like to have the color of the screen's pixel which I point with the mouse cursor Please, help me Thanks in advance
1
by: michael maver | last post by:
Hello, I was just wondering if anyone knew of a way to search the screen for a certain color in Python. I know it is possible to do this in other languages, but I'm not sure how I'd go about...
8
by: visweswaran2830 | last post by:
Hi, Is it possible to getpixel color in vc++/c++ while windows logon screen mode. If possible means, can You tel me the way to get
3
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'm not asking how to do anything, I just need to know why something is happening. I wrote a program that is very simple, it takes a screenshot of a user-defined portion of the screen. Up until now...
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...
1
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.