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
 
Back
Top