Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when i convert intptr to bitmap it show error


A generic error occurred in GDI+.

What I have tried:

IntPtr hbitmap = IntPtr.Zero;
m_SecuBSP.CaptureWindowOption.FingerWindow = (IntPtr)pictureBox1.Handle;
hbitmap = m_SecuBSP.CaptureWindowOption.FingerWindow;
Image img = Image.FromHbitmap(hbitmap);
Updated 8-Aug-18 2:35am
OriginalGriff 8-Aug-18 7:20am    
Repost: Deleted.

1 solution

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();
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900