I created a form with a Panel control that I can draw in. What Im trying to do is scan different pixels within the panel to see what RGB value they have.
I did something like this:
[DllImport("gdi32")]
[return : MarshalAs(UnmanagedaType.U4)] //i guess this part isnt necessary
public static extern int GetPixel (IntPtr hdc, int x, int y);
...
Graphics g = Graphics.FromHwnd(mypanel.Handle);
int nRGB = GetPixel(g.GetHdc(), 10, 10); //nRGB returns -1?!
//now im not even sure if this next part is correct:
Color c = Color.FromArgb(nRGB);
Is there a more simple way of doing what Im trying to do circumventing the need for PInvoke? Also, I was looking at the actual platform sdk GetPixel function and I cant figure out how Im using it incorrectly. The documentation talks about making sure that the x,y of the pixel is within the clipping region. I set a breakpoint and looked at g.VisibleClipBounds and it showed the dimensions of the panel so that seemed okay. I even checked the GetDeviceCaps which returned the RC_BITBLT bit on so everything should be fine and good in the neighborhood...but I still get that blased -1 value. What could be my trouble?
thanks.
Lehel
I did something like this:
[DllImport("gdi32")]
[return : MarshalAs(UnmanagedaType.U4)] //i guess this part isnt necessary
public static extern int GetPixel (IntPtr hdc, int x, int y);
...
Graphics g = Graphics.FromHwnd(mypanel.Handle);
int nRGB = GetPixel(g.GetHdc(), 10, 10); //nRGB returns -1?!
//now im not even sure if this next part is correct:
Color c = Color.FromArgb(nRGB);
Is there a more simple way of doing what Im trying to do circumventing the need for PInvoke? Also, I was looking at the actual platform sdk GetPixel function and I cant figure out how Im using it incorrectly. The documentation talks about making sure that the x,y of the pixel is within the clipping region. I set a breakpoint and looked at g.VisibleClipBounds and it showed the dimensions of the panel so that seemed okay. I even checked the GetDeviceCaps which returned the RC_BITBLT bit on so everything should be fine and good in the neighborhood...but I still get that blased -1 value. What could be my trouble?
thanks.
Lehel