This is what I currenty do to load images in my application:
auto b = ::FreeImage_Load(type, path.c_str());
void *bits;
auto hbmp = CreateDIBSection(
dc,
FreeImage_GetInfo(bitmap),
DIB_RGB_COLORS,
&bits,
0,
0
);
std::memcpy(bits, FreeImage_GetBits(b), size);
It works very well, but I'd like to avoid allocating memory twice - ::FreeImage_Load already stores data in a way that's suitable for dib. Is there a way of calling CreateDIBSection that would prevent allocation and would force dib created that way to use buffer provided by me? If not, is there another method that would allow that?
It seems that providing NULL instead of **ppvBits prevents allocation - is there a way to modify buffer address later? I've also tried tinkering with hSection parameter but dibs created that way were incorrect.
I guess I didn't get your idea wrong.
Maybe you can use
CreateDIBitmapto convertFreeImageimages toHBITMAP.Related Link: How do I convert a FreeImage image to a HBITMAP ?
If you want to use
CreateDIBSection, you can use a non-nullhSectionargument and useCreateFileMappingandMapViewOfFileEx()to create the section, the latter'slpBaseAddressshould point to your bits.Remember to fully initialize the parameters in
MapViewOfFileExandCreateFileMapping.Here is a similar discussion you can refer: How to create an HBITMAP wrapping an existing byte buffer?