The handle returned by
PictureBox.Handle
is not the handle of the bitmap shown in the
PictureBox
(a
HBITMAP
) but the controls window handle (a
HWND
).
To get the image from the PictureBox just use
Image img = pictureBox1.Image;
If you need to get the bitmap handle for that image, create either a new bitmap
Bitmap bmp = new Bitmap(pictureBox1.Image);
IntPtr hBitmap = bmp.GetHbitmap();
or cast the
Image
Bitmap bmp = (Bitmap)pictureBox1.Image;
IntPtr hBitmap = bmp.GetHbitmap();