Search code examples
c#system.drawing

Hbitmap from image


Below creates an image from hbitmap:

IntPtr hbitmap = IntPtr.Zero;
...
...
Image img = Image.FromHbitmap(hbitmap);

Now I need to do that in reverse, I mean I got an image and want hbitmap to use in method

LoadImageFromHBitmap(hbitmap)

I save image in memory than load it from there (if someone help). Thanks!


Solution

  • You're looking for the Bitmap.GetHBitmap method.
    Remember to free the HBitmap.