Error Unable to load bitmap file

Hi,
I have a program that generates bitmaps and another to display them. The display program works fine on bitmaps I cerate manually with paint, but when my other program generates them and I try to load them I get the error unable to load bitmap message.

My program creating bitmaps makes 512x512 24 bit color bmps. Coula anyone tell me what might be wrong?

Thanks

Tim

how are you writing the headers?

what info are you writing as the bitmap header?

Sorry for the late response,

I use:

// File header
m_pBmpFileHeader = new BITMAPFILEHEADER;
m_pBmpFileHeader->bfType = 0x4d42;
m_pBmpFileHeader->bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + dwImgSize;
m_pBmpFileHeader->bfReserved1 = 0;
m_pBmpFileHeader->bfReserved2 = 0;
m_pBmpFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + sizeof(RGBQUAD);

// Bitmap Info header 
m_pBmpInfo = new BITMAPINFO;
m_pBmpInfoHeader = reinterpret_cast<LPBITMAPINFOHEADER>(m_pBmpInfo);
::ZeroMemory(m_pBmpInfoHeader, sizeof(BITMAPINFOHEADER));
m_pBmpInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
m_pBmpInfoHeader->biWidth = Bitmap.bmWidth;
m_pBmpInfoHeader->biHeight = Bitmap.bmHeight;
m_pBmpInfoHeader->biPlanes = 1;
m_pBmpInfoHeader->biBitCount = Bitmap.bmPlanes * Bitmap.bmBitsPixel;
m_pBmpInfoHeader->biSizeImage = dwImgSize;

This code is executed in a create(&bitmap) function, but I did not write it myself so I am not too clear on it.

Thanks

Tim

here’s what i ended up writing about 2 years ago, when i wrote a custom loader/saver.

typedef struct
{
DWORD Filesize; // Filesize in bytes of bitmap
DWORD Reserved;
DWORD DataOffset; // Offset To Actual Bitmap Data
DWORD HeaderSize; // Size Of the Bitmap Header
DWORD Width; // Width In Pixels
DWORD Height; // Height In Pixels
WORD Planes;
WORD BitsPerPixel; // Bits Per Pixel
DWORD Compression;
DWORD DataSize; // Size Of the Bitmap Data
DWORD HPPM; // Horizontal Pixels Per Meter
DWORD VPPM; // Vertical Pixels Per Meter
DWORD Colors; // Colors Used In Bitmap
DWORD IColors; // Important Colors
}BmpHeader;

BmpHeader header;
char FileType[2];

Fill the header:

FileType[0] = ‘B’;
FileType[1] = ‘M’;
header.DataOffset = 54; // this is about the only offset that actually works
header.Filesize = 0x28 + (the file’s size - the header) or (the width * height * (bits per pixel/8);
header.HeaderSize = 0x28; // 40 represents the true size of the header
header.Height = the height;
header.Width = the width;
header.HPPM = 2952; // 75 Horizontal Pixels Per Meter
header.VPPM = 2952; // 75 Vertical Pixels Per Meter
header.BitsPerPixel = 24; // unless your compressing it 24 should do
header.Colors = 0;
header.IColors = 0;
header.Planes = 1;
header.Reserved = 0;
header.Compression = 0;

Write Code:

FILE* fp = fopen(filename,wb);

// write the type
fwrite(FileType,2,1,fp);
// write the full header
fwrite(&header,sizeof(BmpHeader),1,fp);
// then write the data.
fwrite(data,datasize,1,fp);

[This message has been edited by no-one (edited 07-09-2002).]

Thanks for the help