Bool SaveTofile (HbitMap Hbitmap, LPCTSTSTSTSZFILENAME) {HDC HDC; // Each pixel per pixel is int ip ibits; // Define Temperature per pixel in the current resolution. Split size, pixel byte size, bitmap file size, write file byte DWord dwpalettesize = 0, dwbmbitsize = 0, dwdibsize = 0, dwwritten = 0; // bit map attribute structure Bitmap bitmap; / / Bitmap file header structure BitmapFileHeader BMfhdr; // bitmap information head structure BitmapInfoHeader Bi; // points bitmap information head structure lpbitmapinfoheader lpbi; // definition file, allocate memory handle, palette handle, HDIB, HPAL, Holdpal = NULL; // Computational bitmap file Each pixel accounts bytes HDC = Createdc ("Display", NULL, NULL, NULL); IBITS = GetDeviceCaps (HDC, Bitspixel) * getDeDeviceCaps (HDC, Plaso); deletedc (HDC); if (ibits <= 1) wbitcount = 1; ELSE IF (ibits <= 4) wbit = 4; Else IF (ibits <= 8) wbitcount = 8; Else Wbitcount = 24; GetObject (Hbitmap, Sizeof Bitmap), (LPSTR) & Bitmap); bi.biSize = sizeof (BITMAPINFOHEADER); bi.biWidth = Bitmap.bmWidth; bi.biHeight = Bitmap.bmHeight; bi.biPlanes = 1; bi.biBitCount = wBitCount; bi.biCompression = Bi_rgb; bi.bisizeImage = 0; bi.bixpelspermeter = 0; bi.biy PELSPERMETER = 0; bi.bi.bi.bi.Biclrused = 0; dwbmbitsSize = ((Bitmap.bmwidth * wbitcount 31) / 32) * 4 * bitmap.bmHeight; // Distributes memory HDIB = GlobalLoc ( GHND, dwBmBitsSize dwPaletteSize sizeof (BITMAPINFOHEADER)); lpbi = (LPBITMAPINFOHEADER) GlobalLock (hDib); * lpbi = bi; // process palette hPal = GetStockObject (DEFAULT_PALETTE); if (hPal) {hDC = GetDC (NULL Holdpal = SELECTPALETTE (HDC, HPALETTE) HPAL, FALSE) ;RIZEPALETTE (HDC);
} // Get new pixel values under this palette getDibits (HDC, HBitmap, 0, (uint) Bitmap.BmHeiGHT, (LPSTR) LPBI SIZEOF (BitmapInfoHead) DWPALETESIZE, (BitmapInfo *) lpbi, dib_rgb_colors; / / Recovery Paler IF (Holdpal) {SELECTPALETTE (HDC, (HPALETTE) HOLDPAL, TRUE); RealizePalette (HDC); ReleaseDC (NULL, HDC);} // Create bitmap file fH = createfile (lpszfileename, generic_write, 0 , NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (fh == INVALID_HANDLE_VALUE) return FALSE; // the bitmap file header bmfHdr.bfType = 0x4D42; // "BM" dwDIBSize = sizeof (BITMAPFILEHEADER) sizeof (BITMAPINFOHEADER ) dwPaletteSize dwBmBitsSize; bmfHdr.bfSize = dwDIBSize; bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits = (DWORD) sizeof (BITMAPFILEHEADER) (DWORD) sizeof (BITMAPINFOHEADER) dwPaletteSize; // write Bitmap file head Writefile (FH, (LPSTR) & BMFHDR, SIZEOF (BitmapfileHeader), & DWWRITEN, NULL); // Writing bitmap file The remainder of Writefile (FH, (LPSTR) LPBI, DWDIBSIZE, & DWWRITEN, NULL); // Clear Globalunlock (HDI b); GlobalFree (HDIB); CloseHandle (FH); Return true;} code description:
HBitmap: The bitmap handle to save.
LPSZFILENAME: The name of the BMP file to be saved.
Return Value: Successfully returns true, otherwise returns false.