In my application I have to convert an image (image could be in any of the format - PNG, JPEG, BMP etc) to DIB.
This is what I am doing right now,
- Create a movable global memory using GlobalAlloc(GHND,0)
- Create a stream on this global memory using CreateStreamOnHGlobal() API
- Save the given image on to the stream using the encoder for BITMAP
- Then I create another buffer and copy the contents from global memory to the newly created buffer skipping the bitmap file header. This makes the newly allocated buffer a DIB data
- Finally release global memory using GlobalFree() and release the stream.
What I am not comfortable here is, there are a lot of memory being allocated here to convert an image to DIB. I would like to know if there are any other way to achieve this using only minimum amount of memory allocations and de-allocations.