HBITMAP GenericLoadBitmap(string &filepath)
{
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
// check the file signature and deduce its format
// (the second argument is currently not used by FreeImage)
fif = FreeImage_GetFileType(filepath.c_str(), 0);
if(fif == FIF_UNKNOWN) {
// no signature ?
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(filepath.c_str());
}
// check that the plugin has reading capabilities ...
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
// ok, let's load the file
FIBITMAP *dib = FreeImage_Load(fif, filepath.c_str(), 0);
// unless a bad file format, we are done !
CDC *pDC = GetDC();
HBITMAP bitmap = CreateDIBitmap(pDC->GetSafeHdc(), FreeImage_GetInfoHeader(dib),
CBM_INIT, FreeImage_GetBits(dib), FreeImage_GetInfo(dib), DIB_RGB_COLORS);
ReleaseDC(pDC);
FreeImage_Unload(dib);
return bitmap;
}
return NULL;
}