I commonly load images from console apps. Performing operations such as deskewing and colour reduction.
It's also a trivial task to display 1 bit images in the console..
I gave-up on LoadImage a looong time ago - finding that the increased number of formats supported by GDI+ was worth the transition.
Every now and again I forget to initialize GDI+, and the app crashes upon startup. Otherwise, the following function performs adequetly for my needs.
HBITMAP mLoadImg(WCHAR *szFilename)
{
HBITMAP result=NULL;
Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
bitmap->GetHBITMAP(NULL, &result);
delete bitmap;
return result;
}
Before you use this function you must call the following init-code:
static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
static ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Afterwards, you have to shut-down GDI+
Gdiplus::GdiplusShutdown(gdiplusToken);
You'll need to include the gdiplus.h header file and link the gdiplus library