Click here to Skip to main content
15,890,670 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

like

A generic error occurred in GDI+.

What I have tried:

C#
IntPtr hbitmap = IntPtr.Zero;
m_SecuBSP.CaptureWindowOption.FingerWindow = (IntPtr)pictureBox1.Handle;
       
hbitmap = m_SecuBSP.CaptureWindowOption.FingerWindow;
Image img = Image.FromHbitmap(hbitmap);
Posted
Updated 8-Aug-18 2:35am
v2
Comments
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
C#
Image img = pictureBox1.Image;

If you need to get the bitmap handle for that image, create either a new bitmap
C#
Bitmap bmp = new Bitmap(pictureBox1.Image);
IntPtr hBitmap = bmp.GetHbitmap();
or cast the Image
C#
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