bitmap保存

来源:互联网 发布:精仿雨轩qq教程网源码 编辑:程序博客网 时间:2024/05/16 15:28
 void SaveBitmap(DWORD height, DWORD width, char* pdata) {BITMAPFILEHEADER   bmfHeader = {0};        BITMAPINFOHEADER   bi = {0};bi.biSize = sizeof(BITMAPINFOHEADER);        bi.biWidth = bmpScreen.bmWidth;        bi.biHeight = bmpScreen.bmHeight;      bi.biPlanes = 1;        bi.biBitCount = 32;        bi.biCompression = BI_RGB;        bi.biSizeImage = 0;      bi.biXPelsPerMeter = 0;        bi.biYPelsPerMeter = 0;        bi.biClrUsed = 0;        bi.biClrImportant = 0;DWORD dwBmpSize = ((width * bi.biBitCount + 31) / 32) * 4 * height;// Add the size of the headers to the size of the bitmap to get the total file size    DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//Offset to where the actual bitmap bits start.    bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);         //Size of the file    bmfHeader.bfSize = dwSizeofDIB;         //bfType must always be BM for Bitmaps    bmfHeader.bfType = 0x4D42; //BMHANDLE hFile = CreateFile(L"test.bmp", GENERIC_WRITE, 0,  NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);DWORD dwBytesWritten = 0;    WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);    WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);    WriteFile(hFile, (LPSTR)pdata, dwBmpSize, &dwBytesWritten, NULL);CloseHandle(hFile); } 

原创粉丝点击