瞧 This function writes cbitmap into the BMP file

zhaozj2021-02-08  234

First, this function can only target the 24 colors of Bitmap.

void CAppDlg :: WriteBmp (CBitmap * PBitmap) {BITMAPINFO * m_pBMI; BYTE * m_pDIBData; BITMAPFILEHEADER bfh; BITMAPINFOHEADER bi; BITMAP BM; PBitmap-> GetObject (sizeof (BM), & BM); CClientDC dc (this); bi.biSize = sizeof (BitmapInfoHeader); bi.biwidth = bm.bmwidth; bi.biheight = bm.bmHeight; bi.biplanes = 1; bi.biBitcount = 24; bi.bi.bi.bi.bi.bisizeImage = 0; bi.bixpelspermeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; bfh.bfType = 0x4d42; bfh.bfOffBits = sizeof (bfh) sizeof (BITMAPINFOHEADER); bfh.bfSize = bfh.bfOffBits BM. BMWIDTH * 3; bfh.bfreserved1 = 0; bfh.bfreserved2 = 0; m_pbmi = (bitmapinfo *) New char [sizeof (bitmapinfo)]; m_pdibdata = (byte *) new char [bfh.bfsize-bfh. bfOffBits]; memcpy (m_pBMI, & bi, sizeof (BITMAPINFOHEADER)); GetDIBits (dc.GetSafeHdc (), (HBITMAP) PBitmap-> GetSafeHandle (), 0l, (DWORD) bi.biHeight, (LPVOID) m_pDIBData, (LPBITMAPINFO) M_PBMI, (DWORD) DIB_RGB_COLORS; cfile file; if (! file.open (m_filename, cfile :: modecreate | cfile :: modewrite) ) {MessageBox ("Error!"); Return; file.write; file.write (M_PBMI, SIZEOF (BitmapInfoHead); file.write (m_pdibdata, bm.bmwidth * bm.bmheight * 3); file.close (); delete m_pbmi; delete m_pdibdata;

}

In fact, it's simple! There is a source code in the GetPicture software of this site.

转载请注明原文地址:https://www.9cbs.com/read-3165.html

New Post(0)