下面提到的代码;在 32 位机器上运行良好,但在 64 位机器上无法运行..
任何想法/建议 - 以及如何解决这个问题???伙计们,你们怎么看 - 在 64 位机器中保存图像 8 位 BMP
void BMPFile::SaveBMP(char* fileName,BYTE * buf,UINT width,UINT height)
{
short res1=0;
short res2=0;
long pixoff=54;
long compression=0;
long cmpsize=0;
long colors=0;
long impcol=0;
char m1='B';
char m2='M';
DWORD widthDW = WIDTHBYTES(width *24);
long bmfsize=sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) +
widthDW * height;
long byteswritten=0;
BITMAPINFOHEADER header;
header.biSize=40; // header size
header.biWidth=width;
header.biHeight=height;
header.biPlanes=1;
header.biBitCount=24; // RGB encoded, 24 bit
header.biCompression=BI_RGB; // no compression
header.biSizeImage=0;
header.biXPelsPerMeter=0;
header.biYPelsPerMeter=0;
header.biClrUsed=0;
header.biClrImportant=0;
FILE *fp;
fp=fopen(fileName,"wb");
if (fp==NULL)
{
return;
}
// should probably check for write errors here...
fwrite((BYTE *)&(m1),1,1,fp); byteswritten+=1;
fwrite((BYTE *)&(m2),1,1,fp); byteswritten+=1;
fwrite((long *)&(bmfsize),4,1,fp); byteswritten+=4;
fwrite((int *)&(res1),2,1,fp); byteswritten+=2;
fwrite((int *)&(res2),2,1,fp); byteswritten+=2;
fwrite((long *)&(pixoff),4,1,fp); byteswritten+=4;
fwrite((BITMAPINFOHEADER *)&header,sizeof(BITMAPINFOHEADER),1,fp);
byteswritten+=sizeof(BITMAPINFOHEADER);
long row=0;
long rowidx;
long row_size;
row_size=header.biWidth*3;
long rc;
for (row=0;row<header.biHeight;row++)
{
rowidx=(long unsigned)row*row_size;
// write a row
rc=fwrite((void *)(buf+rowidx),row_size,1,fp);
if (rc!=1)
{
break;
}
byteswritten+=row_size;
// pad to DWORD
for (DWORD count=row_size;count<widthDW;count++) {
char dummy=0;
fwrite(&dummy,1,1,fp);
byteswritten++;
}
}
fclose(fp);
}