473,799 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4729
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.co mwrote:
>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*********@12 6.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.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*********@12 6.comwrote in message
news:11******** *************@n 67g2000cwd.goog legroups.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*********@12 6.comwrote in message
news:11******** *************@n 67g2000cwd.goog legroups.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
1607
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 I've seen use old code that is no longer supported in .NET. I will pay the first person who posts working code 10 bucks from paypal. I'm desperate, and really want to know how to do this.
1
10044
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 there some way to do this in C#, and if not, how do I do it in unmanaged code? Thanks in advance.
7
3402
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
4701
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 have the Color Depth or "Color Quality" (bits per pixel) of the display adapter (screen) to be 16 bits (Called "Medium (16 bit)" in the Display Properties Control Panel) in order for it to work.
2
2094
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 run the code from this page: http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access This is the cut down version of my code:
8
1436
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 button. The whole screen become black colour. 2. When the user press any key by keyboard. The whole screen changes to red then green, blue and white. 3. The screen back to "normal display".
4
3568
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 getting the pixel colour from a picture file with a given co-ordinate, but is it possible to do it from the whole screen output regardless what application the selected pixel is in? any help would be help. thanks, Chris
0
1573
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 1 shade of green at a time. so if i have a 3 shades of green i need to process it 3 times. but my prof. want it to be done only once. when i load the picture it must remove all the green background. do you have any idea to do this.
8
2112
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 = Graphics.FromImage(imgFont) g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10225
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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 we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.