
Teechart save to bitmap file code#
One function code for HBITMAP to *.bmp file. If (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL))

Copy the array of color indices into the. If (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) Copy the BITMAPINFOHEADER and RGBQUAD array into the file. If (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), Hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + Compute the offset to the array of color indices. Hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + If (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, (array of palette indices) from the DIB. Retrieve the color table (RGBQUAD array) and the bits LpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage) PBITMAPINFOHEADER pbih // bitmap info-header Void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,īITMAPFILEHEADER hdr // bitmap file-header Set biClrImportant to 0, indicating that all of the Pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8 The width must be DWORD aligned unless the bitmap is RLE indices and store the result in biSizeImage. Compute the number of bytes in the array of color If (cClrBits bmiHeader.biClrUsed = (1bmiHeader.biCompression = BI_RGB Pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel Convert the color format to a count of bits.ĬClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel) Įlse if (cClrBits bmiHeader.biSize = sizeof(BITMAPINFOHEADER)

If (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)) Retrieve the bitmap color format, width, and height. This is the code from the MSDN article ( Note that you need to define the errhandler() function): PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp) bmp file using hBitmap = CreateDIBSection() in C Win32

You write: BITMAPFILEHEADER, then BITMAPINFOHEADER, then palette (which you typically don't have when bits/pixel is over 8), then data itself. You typically either create another bitmap using CreateDIBSection, or you get bitmap data with GetDIBits.ĬreateFile, WriteFile writes data into file. Your solution is to copy bitmap into another bitmap with data access (DIB) and then using it data to write into file. There is no API to save into file directly because, generally, having a bitmap handle does not mean you have direct access to bitmap data.
