views:

65

answers:

1

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( ??? );
    }
+2  A: 

Image is 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 a Metafile, then you need to use the Metafile.GetHenhmetafile method to get a handle.

Aaronaught
Thanks for the answer. I was very confused over Image and Bitmap.
Robogal