How to get the color of a pixel in C#

  • Thread starter Thread starter Valerie Hough
  • Start date Start date
V

Valerie Hough

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.
 
The GDI+ FAQ has an article on how to capture a control or the screen.
Essentially GDI+ DC's don't have a bitmap that you can peek so you have to
grab the bitmap from the window or screen and do getpixel on the captured
image.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Check out February's edition of Well Formed.
Non-client drawing, Graphics Transform stack and Flood-Filling
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top