/*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
参数:
pTureColorBmpInfoHeader:表示 是否有现成的BITMAPINFOHEADER结构,如果有,直接用;
width 和 hight:表示 所创建位图的宽和高信息,如果pTureColorBmpInfoHeader为空,需要全部自己创建BITMAPINFOHEADER;
函数:
Create1ByteBmpHeadeInforFrom3ByteBmpHeadeInfor创建BITMAPINFO结构
(当然可以添加一个参数创建任意颜色深度的BITMAPINFOHEADER结构,
这里简单创建256色(灰度或二值化)位图)
...................................................................................................................................*/
BITMAPINFO* Create1ByteBmpHeadeInforFrom3ByteBmpHeadeInfor( BITMAPINFOHEADER *pTureColorBmpInfoHeader = NULL , int width=0, int hight=0 )
{
/*
一个像素点由一个字节表示,是有颜色表的;
BITMAPINFO 结构体是 BITMAPINFOHEADER+颜色表; 这是一个连续的空间;
颜色表 由 RGBQUAD结构体连续组成,RGBQUAD的个数有图片的位数决定,如16色位图,256色位图等等;
*/
static BITMAPINFO* lpNewBmpInfo = (BITMAPINFO *) new BYTE[ ( sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD) ) ];
if ( pTureColorBmpInfoHeader != NULL )
{
memcpy( &(lpNewBmpInfo->bmiHeader) , pTureColorBmpInfoHeader, sizeof(BITMAPINFOHEADER) ); // (BITMAPINFO*)pbufBmpInfoHeader; //三字节位图没有颜色表;BITMAPINFO是BITMAPINFOHEADER+颜色表;
lpNewBmpInfo->bmiHeader.biBitCount = 8; //1字节位图;
}
else
{
memset(lpNewBmpInfo, '/0', sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD) ) ;//不可以注释这句话;
(lpNewBmpInfo->bmiHeader).biSize = 40;
(lpNewBmpInfo->bmiHeader).biWidth = width;
(lpNewBmpInfo->bmiHeader).biHeight = hight;
(lpNewBmpInfo->bmiHeader).biPlanes = 1;
(lpNewBmpInfo->bmiHeader).biBitCount = 8;
/* //这些注释的 BITMAPINFOHEADER 的结构成员在创建位图的时候可以不指定;
(lpNewBmpInfo->bmiHeader).biCompression =BI_RGB; //无压缩;
(lpNewBmpInfo->bmiHeader).biSizeImage = 0; //Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps
(lpNewBmpInfo->bmiHeader).biXPelsPerMeter ;
(lpNewBmpInfo->bmiHeader).biYPelsPerMeter ;
(lpNewBmpInfo->bmiHeader).biClrUsed = 0;
(lpNewBmpInfo->bmiHeader).biClrImportant = 0;
*/
}
for( int i=0;i<256;i++)
{
lpNewBmpInfo->bmiColors[i].rgbRed=i;
lpNewBmpInfo->bmiColors[i].rgbGreen=i;
lpNewBmpInfo->bmiColors[i].rgbBlue=i;
lpNewBmpInfo->bmiColors[i].rgbReserved=0;
}
return lpNewBmpInfo;
}