I have a function that takes in a Handle to an image:
DoSomethingWithImage( int imageHandle)
{
}
In my main, I have an Image myImage, which resides in memory.
How can I get a Handle to myImage, so that I can pass in that Handle to DoSomethingWithImage() ?
main()
{
//memorySTream is a byte[]
Image myImage = Image.FromStream(memoryStream, true);
DoSomethingWithImage( ??? );
}
Imageis just the abstract base class; descendants aren’t necessarily guaranteed to even have a Windows handle. You need to know the specific type of image – and so does the SDK you’re using, most likely; it is probably assuming that the handle corresponds to a specific format (I would guess bitmap).If the image is in fact a
Bitmap, then you would want to use the Bitmap.GetHbitmap method. On the other hand, if the image is really aMetafile, then you need to use the Metafile.GetHenhmetafile method to get a handle.