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?
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).]