Directly Accessing Pixels in A 24-bit Bitmap
This Article WAS Contributed by Zvika Ben-Haim.
Environment: VC5 / 6, WIN95
This Article Describes How To Display 24-Bit (TrueColor) Bitmaps Which Are Created During Run-Time Bi Directly Accessing The Bitmap's bit Image.
The code in this article uses the CDib class, developed by David J. Kruglinski in his book Inside Visual C , 4th edition. The CDib class is copyrighted by Microsoft, and can be used in your programs as long as you mention their name. The CDIB Class Is Included at The End of this Document.
1. CREATE A CDIB Object, And Allocate Memory.
This Will Typically Be Done In CView :: OnInitialUpdate, OR Some Such. It's Done in The Following Way:
// CREATE A Compatible DC
CDC * PDC = Getdc ();
ASSERT (PDC);
CDC DCCompat;
DCCCompat.createCompatiPLEDC (PDC);
ReleaseDC (PDC);
// Allocate Memory for the bitmap
M_PDIB = New CDIB (CSIZE (Xsize, Ysize), // Size of the Bitmap
24); // bits per pixel
Verify (M_PDIB-> CreateSection (& DCCompat)); // Allocate Memory for Bitmap
2. Fill The Bitmap Data.
You now have a memory region, allocated by Windows, in which you can write the output information. This memory region is accessed from m_pDib-> m_lpImage, and contains a series of three-byte (R, G, B) pixels. As an Example, You Can Get a nice rainbow-color image sale the folowing code:
INT X, Y;
BYTE * DIBITS = m_pdib-> m_lpimage;
For (x = 0; x FOR (Y = 0; Y * (Dibits ) = DOC (x, y); // red * (Dibits ) = DOC (Doc.xsize () - x-1, y); // Green * (Dibits ) = DOC (x, doc.ysize () - Y-1); // blue } Where we buy the function doc, Defined As Follows (Intended for Bitmaps of Size 512x512 Pixels, More Or LESS): Byte Doc (INT X, INT Y) { Return (Byte) (SQRT (x * x y * y) / 4); } 3. Display the bitmap. From With CView :: OnDraw, Use the Following to Display The Bitmap: M_PDIB-> DRAW (PDC, M_RectDraw.Topleft (), m_rectdraw.size ()); where m_rectDraw is a logical-coordinate rectangle defining the position in which we want to place the bitmap. The bitmap is shrunk or expanded using the StretchDIBits function so that it will fit into this rectangle. 4. DELETE The DIB. Don't forget to deallocate the cdib object when're done. The constructor deallocates all memory associate with the the actual image. Delete M_PDIB; File: cdib.h - CDIB Class Header File // CDIB.H Declaration for Inside Visual C CDIB Class #ifndef _INSIDE_VISUAL_CPP_CDIB #define _INSIDE_VISUAL_CPP_CDIB Class CDIB: Public COBJECT { ENUM Alloc, Crtalloc, Heapalloc}; Declare_serial (CDIB) PUBLIC: LPVOID M_LPVCOLORTABLE; Hbitmap m_hbitmap; LPBYTE M_LPIMAGE; // Starting Address Of Dib Bits LPbitmapInfoHeader M_LpBMIH; // Buffer Containing The BitmapInfoHeader Private: Hglobal M_HGLOBAL; // for External Windows WE NEED TO FREE // could be allocated by this class or allocated externally Alloc m_nbmihalloc; Alloc M_NImageAlloc; DWORD M_DWSIZEIMAGE; // of Bits - Not BitmapInfoHeader or BitmapfileHeader INT M_NCOLORTABLEENTRIES; Handle M_HFILE; Handle M_HMAP; LPVOID M_LPVFILE; HPALETTE M_HPALETTE; PUBLIC: CDIB (); CDIB (CSIZE SIZE, INT NbitCount); // Builds BitmapInfoHeader ~ CDIB (); Int getsizeImage () {return m_dwsizeImage;} Int getsizeheader () {RETURN SIZEOF (BitmapInfoHeader) SizeOf (RGBQUAD) * m_ncolortablentries;} csize getdimensions (); Bool attachmapfile (const char * strpathname); Bool Bshare = false; Bool CopyTomapfile (const char * strpathname); Bool AttachMemory (LPVOID LPVMEM, BOOL BMUSTDELETE = FALSE, HGLOBAL HGLOBAL = NULL); Bool Draw (CDC * PDC, CPoint Origin, CSIZE SIZE); // Until We IMPLEMNT CREATEDIBSECTION HBitmap CreateSecion (CDC * PDC = NULL); UINT USEPALETTE (CDC * PDC, Bool BBACKGROUND = FALSE); Bool Makepalette (); Bool SetSystemPalette (CDC * PDC); Bool Compress (CDC * PDC, Bool BCompress = true); // False Means Decompress Hbitmap CreateBitmap (CDC * PDC); Bool Read (cfile * pfile); Bool Readsection (CFile * Pfile, CDC * PDC = NULL); Bool Write (CFILE * PFILE); Void Serialize (CARCHIVE & A); Void Empty (); Private: Void detachmapfile (); Void ComputePalettesize (int nbitcount); Void computemetrics (); } #ENDIF / / _INSIDE_VISUAL_CPP_CDIB File: cdib.cpp - CDIB Class Definitions // cdib.cpp // new version for Win32 #include "stdafx.h" #include "cdib.h" #ifdef _Debug #define new debug_new #undef this_file Static char this_file [] = __file__; #ENDIF Implement_serial (CDIB, COBJECT, 0); CDIB :: CDIB () { M_HFILE = NULL; m_hbitmap = null; m_hpalette = null; M_nbmihalloc = m_nimagealloc = noalloc; EMPTY (); } CDIB :: CDIB (CSIZE SIZE, INT NBITCOTI) { M_HFILE = NULL; m_hbitmap = null; m_hpalette = null; M_nbmihalloc = m_nimagealloc = noalloc; EMPTY (); Computepalettesize (nbitcount); M_lpbmih = (lpbitmapinfohead) New Char [sizeof (BitmapInfoHeader) sizeof (rgbquad) * m_ncolortablentries]; m_nbmihalloc = crtalloc; M_lpbmih-> bisize = sizeof (bitmapinfohead); m_lpbmih-> biwidth = size.cx; M_lpbmih-> biheight = size.cy; m_lpbmih-> biplanes = 1; M_lpbmih-> bibitcount = nbitcount; M_lpbmih-> bicompression = bi_rgb; m_lpbmih-> bisizeImage = 0; M_LPBMIH-> BixPELSPERMETER = 0; M_lpbmih-> biypelspermeter = 0; M_lpbmih-> biclrused = m_ncolortableentries; M_lpbmih-> biclrimportant = m_ncolortablentries; Computemetrics (); MEMSET (M_LPvColortable, 0, SizeOf (RGBQUAD) * m_ncolortablentries; m_lpimage = null; // no data yet } CDIB :: ~ CDIB () { EMPTY (); } CSIZE CDIB :: getDimensions () { IF (m_lpbmih == null) Return CSIZE (0, 0); Return CSIZE ((int) m_lpbmih-> biwidth, (int) m_lpbmih-> biheight); } Bool CDIB :: AttachMapFile (const char * strpathname, bool bshare) // forreading { // if We open the Same File TWice, Windows Treats It As 2 Separate Files // Doesn't Work with Rare Bmp Files Where # Palette Entries> BICLRUSED Handle Hfile = :: Createfile (strpathname, generic_write | generic_read, BSHARE? File_Share_read: 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL AskERT (HFile! = Invalid_Handle_Value); DWORD dwfilesize = :: getfilesize (hfile, null); Handle Hmap = :: CreateFilemapping (Hfile, NULL, PAGE_READWRITE, 0, 0, NULL); DWORD dwerr = :: getLastError (); IF (HMAP == NULL) { AfxMessageBox ("Empty Bitmap File"); Return False; } LPVOID LPVFILE = :: MapViewoffile (HMAP, File_Map_Write, 0, 0, 0); // map whole file Assert (lpvfile! = Null); IF ((lpbitmapfileHeader) lpvfile -> bftype! = 0x4d42) { AfxMessageBox ("Invalid Bitmap File"); Detachmapfile (); Return False; } AttachMemory ((lpbyte) lpvfile sizeof (bitmapfileHeader); m_lpvfile = lpvfile; m_hfile = HFILE; m_hmap = hmap; Return True; } Bool CDIB :: CopyTomapFile (const char * strpathname) { // Copies Dib to a new file, Releases Prior Pointers // if you previously use creation, The HbitMap Will Be Null (and unusable) BitmapfileHeader BMFH; BMFH.BFTYPE = 0x4d42; // 'bm' BMFH.BFSIZE = M_dwsizeImage Sizeof (BitmapInfoHead) SizeOf (RGBQUAD) * m_ncolortablentries sizeof (bitmapfilehead); // meaning of bfsize open to interpretation BMFH.BFRESERVED1 = BMFH.BFRESERVED2 = 0; BMFH.BFOFFBITS = Sizeof (BitmapfileHeader) Sizeof (BitmapInfoHeader) SizeOf (RGBQUAD) * m_ncolortablentries; Handle Hfile = :: Createfile (strpathname, generic_write | generic_read, 0, null, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); AskERT (HFile! = Invalid_Handle_Value); INT nsize = sizeof (bitmapfileHeader) sizeof (BitmapInfoHeader) SIZEOF (RGBQUAD) * M_NCOLORTABLEENTRIES M_DWSIZEIMAGE; Handle Hmap = :: CreateFilemapping (Hfile, Null, Page_Readwrite, 0, NSize, NULL); DWORD dwerr = :: getLastError (); Assert (hmap! = Null); LPVOID LPVFILE = :: MapViewoffile (HMAP, File_Map_Write, 0, 0, 0); // map whole file Assert (lpvfile! = Null); LPBYTE LPBCURRENT = (lpbyte) lpvfile; Memcpy (LPBCurrent, & BMFH, SIZEOF (BitmapfileHeader); // File HEADER LPBCurrent = Sizeof (BitmapfileHead); LPbitmapInfoHeader lpbmih = (lpbitmapinfohead) lpbcurrent; Memcpy (lpbcurrent, m_lpbmih, SizeOf (BitmapInfoHeader) sizeof (rgbquad) * m_ncolortablentries); // info LPBCurrent = SizeOf (BitmapInfoHeader) sizeof (rgbquad) * m_ncolortablentries; memcpy (lpbcurrent, m_lpimage, m_dwsizeImage); // bit Image DWORD DWSIZEIMAGE = m_dwsizeImage; EMPTY (); m_dwsizeimage = dwsizeImage; M_nbmihalloc = m_nimagealloc = noalloc; m_lpbmih = lpbmih; m_lpimage = lpbcurrent; m_hfile = HFILE; m_hmap = hmap; m_lpvfile = lpvfile; ComputePalettesize (M_LPBMIH-> BIBITCOTINT); Computemetrics (); Makepalette (); Return True; } Bool CDIB :: AttachMemory (LPVoid LPVMEM, Bool Bmustdelete, Hglobal Hglobal) { // Assumes Contiuous BitmapInfoHeader, Color Table, Image // Color Table Could Be Zero Length EMPTY (); M_HGLOBAL = HGLOBAL; IF (bmustdelete == false) { m_nbmihalloc = noalloc; } Else { m_nbmihalloc = ((hglobal == null)? crtalloc: HeapAlloc); } Try { M_LpBMIH = (lpbitmapinfoheader) lpvmem; Computemetrics (); ComputePalettesize (M_LPBMIH-> BIBITCOTINT); M_LpiMage = (lpbyte) M_LPVCOLORTABLE SIZEOF (RGBQUAD) * m_ncolortablentries; Makepalette (); } Catch (CEXCEPTION * PE) { AfxMessageBox ("attachmemory error"); PE-> delete (); Return False; } Return True; } UINT CDIB :: UsePalette (CDC * PDC, Bool BBACKGROUND / * = FALSE * / { IF (m_hpalette == null) return 0; HDC HDC = PDC-> GetsafeHDC (); :: SelectPalette (HDC, M_HPALETTE, BBACKGROUND); Return :: REALIZEPALETTE (HDC); } Bool CDIB :: Draw (CDC * PDC, CPoint Origin, CSIZE SIZE) { IF (m_lpbmih == null) Return False; IF (M_HPALETTE! = null) { :: SelectPalette (PDC-> GetsafeHDC (), M_HPALETTE, TRUE; } PDC-> SetStretchBltmode (Coloroncolor); :: Stretchdibits (PDC-> getsafehdc (), Origin.x, Origin.y, size.cx, size.cy, 0, 0, m_lpbmih-> biwidth, m_lpbmih-> biheight, M_LPImage, (lpbitmapinfo) M_LPBMIH, DIB_RGB_COLORS, SRCCOPY; Return True; } Hbitmap CDIB :: CreateSection (CDC * PDC / * = NULL * /) { IF (m_lpbmih == null) Return NULL; IF (m_lpimage! = null) return null; // can only do this if Image Doesn't exist m_hbitmap = :: createDibsection (pdc-> getsafehdc (), (lpbitmapinfo) M_LPBMIH, DIB_RGB_COLORS, (LPVOID *) & M_LPImage, NULL, 0); AskERT (M_LPImage! = NULL); Return M_Hbitmap; } Bool CDIB :: Makepalette () { // Makes a Logical Palette (M_HPALETTE) from the Dib's Color Table // this Palette Will Be Selected and realized prior to drawing the dib IF (m_ncolortablentries == 0) Return False; IF (M_HPALETTE! = NULL) :: DeleteObject (m_hpalette); Trace ("CDIB :: MakePalette - M_ncolortableEntries =% D / N", M_ncolortableEntries; LPLOGPALETTE PLOGPAL = (LPLOGPALETTE) New Char [2 * SizeOf (Word) m_ncolortablentries * sizeof (paletteentry)]; PLOGPAL-> paRversion = 0x300; PLOGPAL-> PALNUMENTRIES = M_NCOLORTABLEENTRIES LPRGBQUAD PDIBQUAD = (LPRGBQUAD) M_LPVCOLORTABLE; For (int i = 0; i PLOGPAL-> PALPALENTRY [i] .pered = pdibquad-> rgbred; PLOGPAL-> PALPALENTRY [i] .pegreen = pdibquad-> rgbgreen PLOGPAL-> PALPALENTRY [i] .peblue = pdibquad-> rgbblue; PLOGPAL-> PALPALENTRY [I] .peflags = 0; PDIBQUAD ; } m_hpalette = :: createpalette (plogpal); Delete PlogPal; Return True; } Bool CDIB :: SetSystemPalette (CDC * PDC) { // if the dib doesn't Have a color table, we can use the system's Halftone Paletteif (m_ncolortablentries! = 0) Return False; m_hpalette = :: createhalftonePalette (PDC-> getsafehdc ()); Return True; } HBitmap CDIB :: CreateBitmap (CDC * PDC) { IF (m_dwsizeimage == 0) Return NULL; Hbitmap hbitmap = :: createdibitmap (pdc-> getsafehdc (), m_lpbmih, CBM_INIT, M_LPIMAGE, (LPBitmapInfo) M_LPBMIH, DIB_RGB_COLORS); Assert (hbitmap! = Null); Return hbitmap; } Bool CDIB :: Compress (CDC * PDC, Bool Bcompress / * = true * /) { // 1. Makes GDI Bitmap from EXIXG DIB // 2. Makes a New Dib from GDI Bitmap with Compression // 3. Cleans Up The Original DIB // 4. Puts the new dib in the object IF ((M_LPBMIH-> BIBITCOT! = 4) && (m_lpbmih-> bibitcount! = 8)) Return False; // Compression Supported Only for 4 BPP and 8 BPP DIBS IF (M_Hbitmap) Return False; // CAN't Compress A Dib Section! Trace ("Compress: Original Palette Size =% D / N", M_NColortableEntries; HDC HDC = PDC-> GetsafeHDC (); HPALETTE HOLDPALETTE = :: SelectPalette (HDC, M_HPALETTE, FALSE); Hbitmap hbitmap; // temporary IF ((Hbitmap = CreateBitmap (PDC)) == NULL) Return False; INT nsize = sizeof (bitmapinfoheader) sizeof (rgbquad) * m_ncolortablentries; LPbitmapInfoHeader lpbmih = (lpbitmapinfohead) new char [nsize]; Memcpy (lpbmih, m_lpbmih, nsize); // new header IF (bcompress) { Switch (lpbmih-> bibitcount) { Case 4: LPBMIH-> BiCompression = bi_rle4; Break; Case 8: LPBMIH-> bicompression = bi_rle8; Break; DEFAULT: Assert (false); } // Calls getDibits with null data pointer to get size of compressed dib IF (! :: getDibits (pdc-> getsafehdc (), hbitmap, 0, (uint) lpbmih-> biheight, null, (lpbitmapinfo) lpbmih, dib_rgb_colors) { AfxMessageBox ("Unable to Compress this Dib"); // probably a problem with the color table :: DeleteObject (Hbitmap); delete [] lpbmih; :: SelectPalette (HDC, Holdpalette, False); Return False; } IF (lpbmih-> bisizeImage == 0) { AfxMessageBox ("Driver CAN't Do Compression"); :: DeleteObject (Hbitmap); delete [] lpbmih; :: SelectPalette (HDC, Holdpalette, False); Return False; } Else { m_dwsizeimage = lpbmih-> bisizeImage; } } Else { LPBMIH-> Bicompression = Bi_RGB; // Decompress // figure the Image size from the bitmap width and height DWORD DWBYTES = (DWORD) LPBMIH-> BIWIDTH * LPBMIH-> BIBITCOUNT) / 32; IF ((DWORD) LPBMIH-> BIWIDTH * LPBMIH-> BIBITCOUNT)% 32) { DWBYTES ; } DWBYTES * = 4; M_dwsizeImage = dwbytes * lpbmih-> biheight; // no compression LPBMIH-> bisizeiMage = m_dwsizeImage; } // Second GetDibits Call to make Dib LPBYTE LPIMAGE = (lpbyte) New char [m_dwsizeimage]; Verify (:: getDibits (pdc-> getsafehdc (), hbitmap, 0, (uint) lpbmih-> biheight, LPIMAGE, (LPBitmapInfo) lpbmih, dib_rgb_colors); Trace ("DIB SuccessFully Created - Height =% D / N", LPBMIH-> Biheight); :: DeleteObject (Hbitmap); EMPTY (); m_nbmihalloc = m_nimagealloc = crtalloc; m_lpbmih = lpbmih; M_LPIMAGE = LPIMAGE; Computemetrics (); ComputePalettesize (M_LPBMIH-> BIBITCOTINT); Makepalette (); :: SelectPalette (HDC, Holdpalette, False); Trace ("Compress: New Palette Size =% D / N", M_NCOLORTABLEENTRIES); Return True; } Bool CDIB :: Read (CFile * Pfile) { // 1. Read file header to get size of info hdr color table // 2. Read info HDR (TO GET Image Size) and Color Table // 3. Read image // can't use bfsize in file header EMPTY (); Int ncount, nsize; BitmapfileHeader BMFH; Try { Ncount = Pfile-> Read ((LPVOID) & BMFH, SIZEOF (BitmapFileHead); IF (ncount! = sizeof (bitmapfileHead) { Throw new CEXCEPTION; } IF (BMFH.BFTYPE! = 0x4d42) { Throw new CEXCEPTION; } Nsize = BMFH.BFOFFBITS - SIZEOF (BitmapfileHeader); M_LpBMIH = (lpbitmapinfoheader) New char [nsize]; m_nbmihalloc = m_nimagealloc = crtalloc; Ncount = pfile-> read (m_lpbmih, nsize); // Info HDR & Color Table Computemetrics (); ComputePalettesize (M_LPBMIH-> BIBITCOTINT); Makepalette (); M_Lpimage = (lpbyte) new char [m_dwsizeimage]; ncount = pfile-> read (m_lpimage, m_dwsizeimage); // image only } Catch (CEXCEPTION * PE) { AfxMessageBox ("Read Error"); PE-> delete (); Return False; } Return True; } Bool CDIB :: Readsection (CFile * Pfile, CDC * PDC / * = NULL * /) { // new function reads bmp from disk and create a dib section // allows modification of bitmaps from disk // 1. Read file header to get size of info HDR Color Table // 2. Read Info HDR (TO GET Image Size) and Color Table // 3. Create Dib Section Based on Header Parms // 4. Read image Into memory That CreateDibsection Allocates EMPTY (); Int ncount, nsize; BitmapfileHeader BMFH; Try { Ncount = Pfile-> Read ((LPVOID) & BMFH, SIZEOF (BitmapFileHead); IF (ncount! = sizeof (bitmapfileHead) { Throw new CEXCEPTION; } IF (BMFH.BFTYPE! = 0x4d42) { Throw new CEXCEPTION; } Nsize = BMFH.BFOFFBITS - SIZEOF (BitmapfileHeader); M_LpBMIH = (lpbitmapinfoheader) new char [nsize]; m_nbmihalloc = crtalloc; m_nimagealloc = noalloc; Ncount = pfile-> read (m_lpbmih, nsize); // Info HDR & Color Table IF (m_lpbmih-> bicompression! = bi_rgb) { Throw new CEXCEPTION; } Computemetrics (); ComputePalettesize (M_LPBMIH-> BIBITCOTINT); Makepalette (); UsePalette (PDC); m_hbitmap = :: createDibsection (pdc-> getsafehdc (), (lpbitmapinfo) M_LPBMIH, DIB_RGB_COLORS, (LPVOID *) & M_LPImage, NULL, 0); AskERT (M_LPImage! = NULL); ncount = pfile-> read (m_lpimage, m_dwsizeimage); // image only } Catch (CEXCEPTION * PE) { AfxMessageBox ("Readsection Error"); PE-> delete (); Return False; } Return True; } Bool CDIB :: Write (cfile * pfile) { BitmapfileHeader BMFH; BMFH.BFTYPE = 0x4d42; // 'bm' INT nsizehdr = sizeof (bitmapinfohead) sizeof (rgbquad) * m_ncolortablentries; BMFH.BFSIZE = 0; // bmfh.bfsize = sizeof (bitmapfileHeader) nsizehdr m_dwsizeImage // meaning of bfsize open to interpretation (bytes, words, dwords?) - We Won't use it it BMFH.BFRESERVED1 = BMFH.BFRESERVED2 = 0; BMFH.BFOFFBITS = Sizeof (BitmapfileHeader) Sizeof (BitmapInfoHeader) SizeOf (RGBQUAD) * m_ncolortablentries; Try { Pfile-> Write ((LPVOID) & BMFH, SIZEOF (BitmapfileHead); Pfile-> Write ((LPVOID) M_LPBMIH, NSIZEHDR); Pfile-> Write ((LPVOID) M_LPImage, M_dwsizeImage; } Catch (CEXCEPTION * PE) { PE-> delete (); AfxMessageBox ("Write Error"); Return False; } Return True; } Void CDIB :: Serialize (CARCHIVE & A) { DWORD DWPOS; DWPOS = ar.getfile () -> getPosition (); Trace ("CDIB :: Serialize - POS =% D / N", DWPOS); Ar.flush (); dwpos = ar.getfile () -> getPosition (); Trace ("CDIB :: Serialize - POS =% D / N", DWPOS); IF (ar.isstoring ()) { Write (ar.getfile ()); } Else { Read (ar.getfile ()); } } // Helper Functions Void CDIB :: ComputePalettesize (int nbitcount) { IF ((m_lpbmih == null) || (m_lpbmih-> biclrused == 0)) { Switch (nbitcount) { Case 1: M_ncolortablentries = 2; Break; Case 4: m_ncolortablentries = 16; Break; Case 8: M_ncolortablentries = 256; Break; Case 16: Case 24: Case 32: M_ncolortablentries = 0; Break; DEFAULT: Assert (false); } } Else { M_ncolortablentries = m_lpbmih-> biclrused; } Assert ((m_ncolortablentries> = 0) && (m_ncolortablentries <= 256)); } Void CDIB :: ComputeMetrics () { IF (m_lpbmih-> bisize! = sizeof (bitmapinfoheader) { "NOT A Valid Windows Bitmap - Probably AN OS / 2 Bitmap / N"); Throw new CEXCEPTION; } m_dwsizeimage = m_lpbmih-> bisizeImage; IF (m_dwsizeizeimage == 0) { DWORD DWBYTES = (DWORD) M_LPBMIH-> BIWIDTH * M_LPBMIH-> BIBITCOUNT) / 32; IF ((DWORD) M_LPBMIH-> BIWIDTH * M_LPBMIH-> BIBITCOUNT)% 32) { DWBYTES ; } DWBYTES * = 4; M_dwsizeImage = dwbytes * m_lpbmih-> biheight; // no compression } M_LPVCOLORTABLE = (LPBYTE) M_LPBMIH SIZEOF (BitmapInfoHeader); } Void CDIB :: EMPTY () { // this is supposed to clean Up Whatver is in the DIB Detachmapfile (); IF (m_nbmihalloc == crtalloc) { delete [] m_lpbmih; } Else IF (m_nbmihalloc == Heapalloc) { :: GlobalUnlock (m_hglobal); :: GlobalFree (M_HGLOBAL); } IF (m_nimagealloc == crtalloc) delete [] m_lpimage; IF (m_hpalette! = null) :: deleteObject (m_hpalette); if (m_hbitmap! = null) :: deleteObject (m_hbitmap); M_nbmihalloc = m_nimagealloc = noalloc; m_hglobal = NULL; m_lpbmih = null; M_LPIMAGE = NULL; m_lpvcolortable = null; M_ncolortablentries = 0; m_dwsizeimage = 0; M_LPVFile = NULL; m_hmap = null; M_HFILE = NULL; m_hbitmap = null; m_hpalette = null; } Void CDIB :: DetachMapFile () { IF (m_hfile == null) return; :: UnmapViewOffile (M_LPVFile); :: CloseHandle (M_HMAP); :: CloseHandle; M_HFile; M_HFILE = NULL; }