//---------------------------------------------------------------------------
struct TGrayBMPHeader
{
BITMAPINFOHEADER header;
RGBQUAD pals[256];
TGrayBMPHeader();
void SetInfo(int w,int h)
{
header.biWidth = w;
header.biHeight = -h;
}
};
//---------------------------------------------------------------------------
TGrayBMPHeader::TGrayBMPHeader()
{
header.biSize = sizeof(header);
header.biPlanes = 1;
header.biBitCount = 8;
header.biCompression = BI_RGB;
header.biSizeImage = 0;
header.biXPelsPerMeter = 120;
header.biYPelsPerMeter = 120;
header.biClrUsed = 0;
header.biClrImportant = 0;
for(int i=0;i<256;i++)
{
pals.rgbBlue = (unsigned char)i;
pals.rgbGreen = (unsigned char)i;
pals.rgbRed = (unsigned char)i;
pals.rgbReserved = 0;
}
}
//---------------------------------------------------------------------------
void DrawBMP(HDC dc,char *data)//128*128
{
TGrayBMPHeader header;
header.header.biWidth = 128;
header.header.biHeight = -128;
//用new分配的内存有时在NT上不能显示出来,
//不知道为什么.
unsigned char *tp = (unsigned char *)GlobalAlloc(GMEM_FIXED,128*128);
//注意每行必须对齐到4字节,否则有问题
memcpy(tp,data,128*128);
StretchDIBits(dc,0,0,128,128,0,0,128,128,tp,(BITMAPINFO *)&header,DIB_RGB_COLORS,SRCCOPY);
GlobalFree(tp);
}