Problem with 24-bit bitmaps
Posted: Wed Jun 28, 2006 10:47 pm
At the moment, I'm having trouble loading the following 24-bit colour bitmap http://www.nicholaskingsley.co.uk/MiscT ... 000001.BMP - for some reason LoadImage fails, although if its converted to 256 colours, its fine.
The only thing I can think of is that the bitmap format is slightly different to what it should be (its actually created in a DLL), but then Paint and most other programs can load it okay.
Mind you, it appears that 24-bitmaps saved from Paint wont work - although 256-bit colours will.
This is the code for loading the bitmap :
And this is the code that saves it :
The only thing I can think of is that the bitmap format is slightly different to what it should be (its actually created in a DLL), but then Paint and most other programs can load it okay.
Mind you, it appears that 24-bitmaps saved from Paint wont work - although 256-bit colours will.
This is the code for loading the bitmap :
Code: Select all
If LoadImage(1,"c:\G000003.BMP")=0
MessageRequester("Failed","Failed")
EndIfCode: Select all
signed short CMappy::saveBitmaps(unsigned char *temp24Buffer,DWORD numToDo,DWORD i)
{
BITMAPINFOHEADER bih;
BITMAPFILEHEADER bmfh;
int nBitsOffset;
LONG lImageSize;
LONG lFileSize;
TCHAR fileName[MAX_PATH+1];
FILE *pFile;
memset (&bih, 0, sizeof(BITMAPINFOHEADER));
bih.biSize = sizeof (BITMAPINFOHEADER);
bih.biWidth =m_dBlockWidth;
bih.biHeight = 0-m_dBlockHeight;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = BI_RGB;
bih.biSizeImage = ((((bih.biWidth * bih.biBitCount)
+ 31) & ~31) >> 3) * bih.biHeight;
nBitsOffset = sizeof(BITMAPFILEHEADER) + bih.biSize;
lImageSize = bih.biSizeImage;
lFileSize = nBitsOffset + lImageSize;
bmfh.bfType = 'B'+('M'<<8);
bmfh.bfOffBits = nBitsOffset;
bmfh.bfSize = lFileSize;
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
//Write the bitmap file header
swprintf(fileName,_T("%s\\G%06d.BMP"),GRAPHIC_PATH,i);
if ((pFile=_wfopen(fileName,_T("wb")))!=NULL)
{
size_t nWrittenFileHeaderSize;
size_t nWrittenInfoHeaderSize;
size_t nWrittenDIBDataSize;
nWrittenFileHeaderSize = fwrite(&bmfh, 1, sizeof(BITMAPFILEHEADER), pFile);
//And then the bitmap info header
nWrittenInfoHeaderSize = fwrite(&bih,1, sizeof(BITMAPINFOHEADER), pFile);
//Finally, write the image data itself
//-- the data represents our drawing
nWrittenDIBDataSize = fwrite(temp24Buffer, 1, numToDo, pFile);
fflush(pFile);
fclose(pFile);
return ERROR_OK;
}
else
{
return ERROR_FILENOTOPENED;
}
}