473,396 Members | 1,827 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,396 software developers and data experts.

How to get the color of the specified pixel in the screen?

I want to get the color of the specified pixel in the screen.
Firstly I get the position of the cursor:
//Get the position of cursor.
Point position = Cursor.Position;

Next I want to get the color using the position of the cursor.
Anybody here can show me some demo codes?

Thanks.

Dec 15 '06 #1
6 4682
Hello Hooyoo,

Use GetPixel method of WinAPI.
Sample is there http://pinvoke.net/default.aspx/gdi32/GetPixel.html

HI want to get the color of the specified pixel in the screen.
HFirstly I get the position of the cursor:
H//Get the position of cursor.
HPoint position = Cursor.Position;
HNext I want to get the color using the position of the cursor.
HAnybody here can show me some demo codes?
H>
HThanks.
H>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 15 '06 #2
Michael Nemtsev <ne*****@msn.comwrote:
>Use GetPixel method of WinAPI.
Sample is there http://pinvoke.net/default.aspx/gdi32/GetPixel.html
Looking at that page, I think it has a leak. It should
ReleaseDC(hwnd,hdc) the hdc that it acquired.
Ah, it's a wiki. I guess I'll go and change it.

--
Lucian
Dec 15 '06 #3
"Hooyoo" <zh*********@126.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
>I want to get the color of the specified pixel in the screen.
Firstly I get the position of the cursor:
//Get the position of cursor.
Point position = Cursor.Position;

Next I want to get the color using the position of the cursor.
Anybody here can show me some demo codes?
In addition to what Michael wrote (I'm assuming there's no practical way to
get a Graphics object representing the screen DC in .NET)...

Keep in mind that reading from the video card frame buffer is slow, at least
with AGP cards. So hopefully you don't need to get the pixel's color very
frequently.

Also keep in mind that when an application is using an overlay buffer
(pretty common with video media players, not very common with anything
else), getting the color of a pixel within the overlay will not get the
actual color being displayed there. It will usually be black, but if not it
will be some other default color rather than the pixel you're actually
seeing.

Pete
Dec 15 '06 #4
Thank you, Michael.
But actually I don't like use API in C#, I think it makes ungraceful
codes.
So hopefully there are some methonds of .Net Class Libraries can
implement that.
Michael Nemtsev wrote:
Hello Hooyoo,

Use GetPixel method of WinAPI.
Sample is there http://pinvoke.net/default.aspx/gdi32/GetPixel.html

HI want to get the color of the specified pixel in the screen.
HFirstly I get the position of the cursor:
H//Get the position of cursor.
HPoint position = Cursor.Position;
HNext I want to get the color using the position of the cursor.
HAnybody here can show me some demo codes?
H>
HThanks.
H>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 15 '06 #5
Hi,

"Hooyoo" <zh*********@126.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
Thank you, Michael.
But actually I don't like use API in C#, I think it makes ungraceful
codes.
So hopefully there are some methonds of .Net Class Libraries can
implement that.
Unfortunately you will have to use it, there is nothing in the framework for
doing what you want. it's after all platform dependand.

There is nothing wrong in using the win API you know
--
Ignacio Machin
machin AT laceupsolutions com
Dec 15 '06 #6
Thanks, got it.
"Ignacio Machin ( .NET/ C# MVP ) дµÀ£º
"
Hi,

"Hooyoo" <zh*********@126.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
Thank you, Michael.
But actually I don't like use API in C#, I think it makes ungraceful
codes.
So hopefully there are some methonds of .Net Class Libraries can
implement that.

Unfortunately you will have to use it, there is nothing in the framework for
doing what you want. it's after all platform dependand.

There is nothing wrong in using the win API you know
--
Ignacio Machin
machin AT laceupsolutions com
Dec 16 '06 #7

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

Similar topics

2
by: Arthur | last post by:
Given the coordinates of a point on the screen (such as 185,185), how do you get the color of said point using VB.NET 2003. I have looked EVERYWHERE for this, but to no avail. All the examples...
1
by: Valerie Hough | last post by:
I have an object derived from Control and I place an icon in it during Paint handler. I now want to get the color of a particular pixel in my control. In C++ I could use CDC::GetPixel(x,y). Is...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
5
by: hayworth | last post by:
How do I get the color depth of the screen/display adapter with vb.net 2003? Background: We're having transparency problems (long side story and known Windows "bug") that requires our systems to...
2
by: kuratkull | last post by:
Hello, I haven't asked If I wasn't really confused :) OK, so I am just beginning SDL programming in C, and I was running fine, until I tried getting a pixel colour. Basically, I am trying to...
8
by: =?Utf-8?B?S2Vsdmlu?= | last post by:
Hi all, I am writing an application to detect the dead pixel of LCD panel by using visual C++ (MFC). My flow is follow: 1. Display a dialog with a start button. When the user press the start...
4
by: cjstuttle | last post by:
Could anyone help me, I'm a python noob and need some help. im trying to find some code that will, given a screen co-ordinate, will give me the colour of that pixel in RGB. i have found a lot about...
0
by: icebeta | last post by:
hi, I'm doing a project in c# that removes the green background in a picture, like a green screen effect in movies. i already made it partially working. but the problem is that it only remove...
8
by: Massimiliano | last post by:
Hi all. How I can retreive a dimension in pixel of a character draw with graphics.drawstring(...). For example: imgFont = New Bitmap(48, 48) ' for now the dimension is fixed g =...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...

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.