I am trying to load a non-bmp image (png in my case) into a Bitmap/Image instance from a resource in my app. Since the Bitmap constructor only has an overload for a bitmap resource, this is what i've came around:
I allocate memory on the global heap, and then copy the resource data into it. Then I create an IStream for that global memory block (using CreateStreamOnHGlobal) and use the Image/Bitmap constructor that takes that stream. Basically it works, although i am not sure that this is the best way to do it: I've noticed that if I free that memory block after creating the image, it wouldn't be drawn (Calling DrawImage won't produce anything). Which raises two questions:
How do I manage the lifetime of that memory block? I doubt it would get deallocated upon the image's destruction.
Does the Image/Bitmap class uses the png data in it's compressed form and translates it into raw data on each call to DrawImage? Seems very unefficient.
Any sugestions?