33,311
社区成员
发帖
与我相关
我的任务
分享
BYTE* DDBdata = new BYTE[240*180*3];
// BYTE* DIBdata;
WORD width=240;
WORD height=180;
int te,pe,cn;
for(te=0; te<240; te++)
{
for( pe =0 ; pe<180*3;pe++)
{
cn = pe%3 ;
if(cn==0)
{ DDBdata[ te*540 + pe] = 48 ; }
else if (cn==1)
{ DDBdata[ te*540 + pe] = 49 ; }
else
{ DDBdata[ te*540 + pe] = 120 ; }
}
}
// SetKMode(FALSE);
//CBitmap bitmap;// 图片
//HBITMAP dstBmp; //DDB
//bitmap.CreateBitmap(width,height,1,24,DDBdata);// 创建一张DDB位图,获得句柄
//HDC hdcSrc = CreateCompatibleDC(NULL);
//HDC hdcDst = CreateCompatibleDC(NULL);
BITMAPINFOHEADER bih = {0};// 位图信息头
bih.biBitCount = 24;// 每个像素字节大小
bih.biCompression = BI_RGB;
bih.biHeight = height;// 高度
bih.biWidth = width;// 宽度
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = width*height*3;// 图像数据大小 // BI_RGB 格式时必须为
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed=0;
bih.biClrImportant =0 ;
BITMAPFILEHEADER bfh = {0};// 位图文件头
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);// 到位图数据的偏移量
bfh.bfSize = bfh.bfOffBits + width*height*3; // 文件总的大小
bfh.bfType = (WORD)0x4d42; // must be "MB" 0x4d = 77 = M , 0x42 = 66 = B
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0 ;
//BITMAPINFO bi={0};
//bi.bmiHeader=bih;
//dstBmp=CreateDIBSection(hdcDst, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void **)&DIBdata, NULL, 0);
//SelectObject(hdcDst, dstBmp);
//SelectObject(hdcSrc, bitmap);
//BitBlt(hdcDst, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);// 将位图复制到实际的设备环境中
CFile file(_T("124.bmp"),CFile::modeCreate|CFile::modeReadWrite);
file.Write(&bfh,sizeof(bfh));
file.Write(&bih,sizeof(bih));
file.Write(DDBdata,width*height*3);
file.Close();