我正在尝试创建一个 .bmp 文件,但无法识别该文件。我究竟做错了什么?
#define ImageWidgh 1920
#define ImageHeight 1080
#define fileSize ImageWidgh*ImageHeight*3+54
struct BMPH
{
short Signature;
long int FileSize,reserved,DataOffest;
}BMPH;
struct BMPIH
{
long int Size,Width,Height;
short Planes,BitCount;
long int Compression,ImageSize,XpixelsPerM,YpixelsPerM,ColorsUsed,ColorImportant;
}BMPIH;
struct BMPCT
{
unsigned char Red,Green,Blue;
}BMPCT;
BMPH *getBMPH()
{
BMPH New;
New.Signature='BM';
New.FileSize=fileSize;
New.reserved=0;
New.DataOffest=54;
return &New;
}
BMPIH *getBMPIH()
{
BMPIH New;
New.Size=40;
New.Width=ImageWidgh;
New.Height=ImageHeight;
New.Planes=1;
New.BitCount=24;
New.Compression=0;
New.ImageSize=0;
New.XpixelsPerM=0;
New.YpixelsPerM=0;
New.ColorsUsed=0;
New.ColorImportant=0;
return &New;
}
BMPCT Pixels [ImageWidgh][ImageHeight];
void writeFile()
{
FILE *file;
file=fopen("D://test.bmp","wb");
fwrite(getBMPH() ,sizeof(BMPH) ,1,file);
fwrite(getBMPIH(),sizeof(BMPIH),1,file);
fwrite(&Pixels ,ImageWidgh*ImageHeight*3,1,file);
fclose(file);
}