none
A generic error occurred in GDI+. RRS feed

  • Question

  • when i convert intptr to bitmap it show error

    like

    A generic error occurred in GDI+.

       IntPtr hbitmap = IntPtr.Zero;
               m_SecuBSP.CaptureWindowOption.FingerWindow = (IntPtr)pictureBox1.Handle;
           
      
                hbitmap = m_SecuBSP.CaptureWindowOption.FingerWindow;
               Image img = Image.FromHbitmap(hbitmap);
             
    Wednesday, August 8, 2018 8:29 AM

All replies

  • hbitmap is 722822
    Wednesday, August 8, 2018 9:00 AM
  • I've found that the error messages you tend to get from the Image control are unfortunately confusing.

    It looks like your problem is that you are trying to use the handle of the PictureBox control as a bitmap handle.

    But the PictureBox is a control that contains an image. It is not an image itself.

    If you want to extract out the contained image you only have to access the Image property:

    Image img = pictureBox1.Image

    • Proposed as answer by cheong00Editor Wednesday, August 8, 2018 9:51 AM
    Wednesday, August 8, 2018 9:36 AM
  • Agreed.

    Also note that you'll want to make a copy of the Image with .Clone() first if you want to lock bits to access the strides data. Otherwise it may choke your control.

    Wednesday, August 8, 2018 9:56 AM
    Answerer
  • thanks sir for reply but  

     m_SecuBSP.CaptureWindowOption.FingerWindow = (IntPtr)pictureBox1.Handle;
           in this picturebox has a handle event means only pointer not exact image

    thats why i am facing problem

    i need  pointer to image

    Wednesday, August 8, 2018 11:06 AM
  • need to convert picturebox1.handle to picturebox1.image

    for that i use FromHbitmap

    plz reply i am searching solution from last two days

    Wednesday, August 8, 2018 11:22 AM
  • What are you really trying to do?

    Because I have already told you that the PictureBox is a control that contains an image, not the image itself. Therefore PictureBox.Handle is going to return you the control's window handle.

    This is not the image handle.

    You use PictureBox.Image if you want a reference to the image, as I showed in my last post.


    Wednesday, August 8, 2018 12:46 PM
  • yes sir , i plz see picturebox1.handle and picturebox.image both are diiferent 

    picturebox1.handle give pointer and picturebox1.picture give exact image

    but with secugen fingerprint dll i got fingerprint in  picturebox1.handle i am facing problem to save thats why if i got picturebox1.image then no problem

    i got picturebox.handle from secugen fingerprint device but i want this in picturebox1.image

    my code is

     BSPError err;


                m_SecuBSP.CaptureWindowOption.WindowStyle = (int)WindowStyle.INVISIBLE;


               m_SecuBSP.CaptureWindowOption.ShowFPImage = true;
            
               m_SecuBSP.CaptureWindowOption.FingerWindow = (IntPtr)pictureBox1.Handle;
               hbitmap = m_SecuBSP.CaptureWindowOption.FingerWindow;       
             
               var image = new Bitmap(Image.FromHbitmap(hbitmap));
               pictureBox1.Image = image;
             

    Wednesday, August 8, 2018 1:10 PM
  • https://msdn.microsoft.com/en-us/library/system.windows.forms.control.handle(v=vs.110).aspx

    same issue i find https://www.experts-exchange.com/questions/20841408/Bitmap-from-HBITMAP-problem.html

    Wednesday, August 8, 2018 1:12 PM
  • all issue is for FromHbitmap
    Wednesday, August 8, 2018 1:15 PM
  • Hi Sapana mahajan,

    You could get image handle via the method named bitmap.GetHbitmap(), like this:

    Bitmap bitmap = (Bitmap)pictureBox1.Image;
    
    Image img = Image.FromHbitmap(bitmap.GetHbitmap());
    
    pictureBox2.Image = img;

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 9, 2018 6:51 AM
    Moderator