How to write CBITMAP to files

xiaoxiao2021-03-06  82

How to write CBITMAP to files

If you have a bitmap handle that has a device-independent bitmap, it is very simple to write a bitmap to the BMP file: in the bitmap content

After writing BitMapInfoHeader information. Three members who need to set BitmapInfoHeader are bftype,

Its value is "BM", BFSIZE, its value is the size of the bitmap, and BFoffbits, its value begins to position

Bit offset.

// WriteDib - Writes a dib to file

// Returns - True on SUCCESS

// szfile - Name of File to Write To

// HDIB - HANDLE OF THE DIB

Bool WriteDIB (LPTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTS

{

BitmapfileHeader HDR;

LpbitmapInfoHeader LPBI;

IF (! HDIB)

Return False;

CFILE FILE;

IF (! file.open (szfile, cfile :: modewrite | cfile :: modete)))

Return False;

LPBI = (lpbitmapinfoheader) HDIB;

Int ncolors = 1 << lpbi-> bibitcount;

// Fill in the Fields of the file header

Hdr.bfType = (Word) ('M' << 8) | 'b'); // is always "BM"

HDr.bfsize = "globalsize" (hdib) sizeof (HDR); hdr.bfreserved1 = "0;"

Hdr.bfreserved2 = "0;" HDR.BFOFFBITS = "(SizeOf (HDR) LPBI-> Bisize

NCOLORS * SIZEOF (RGBQUAD));

// Write the File HEADER

File.write (& HDR, SIZEOF (HDR));

// Write the dib header and the bits

File.write (lpbi, globalsize (hdib));

Return True;

}

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

New Post(0)