Article View: comp.os.ms-windows.programmer.graphics
Article #12Saving a DIB to a file
From: finkcr1
Date: Fri, 19 Jan 1996 14:35
Date: Fri, 19 Jan 1996 14:35
34 lines
2201 bytes
2201 bytes
I'm using VC++ 1.5 and have successfully saved the image I drew in an MDI
child window to a file as a DIB. I used as a model the code in the MS example
program DIBVIEW. The problem is that the bitmap I've saved to the file shows
up as a monochrome bitmap; the colors displayed in the window do not show up.
Here is the code I used to copy the bitmap to a memory DC:
memDC.CreateCompatibleDC(GetDC())
.
.
bm.CreateCompatibleBitmap(&memDC,rect.Width(),rect.Height());
.
.
oldbm = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, rect.Width(),rect.Height(), GetDC(), 0, 0, SRCCOPY);
When I do a GetObject on the bitmap, it says it has 1 bit per pixel. I'm
confused. I don't completely understand the intricacies of palettes, etc.. The
palette associated with the memory DC seems to be OK (20 entries). I call a
routine, WinDibFromBitmap (copied from DIBVIEW), it calls GetDibBits and
passes back a handle to the DIB. It also sets up the BITMAPINFO header and
allows space for the color table. It sets the BiBitCount entry in the
BITMAPINFOHEADER to a value calculated from the product of the BmPlanes and
BmBitsPixel entries in the BITMAP structure. BiBitCount is then used to
determine the number of entries in the color table. The palette is passed to
the routine as an HPALETTE structure. This is selected into a DC and then
RealizePalette is called. This DC (Creates with a GetDC(NULL)) is used as a
parameter to GetDibBits.
If there are any DIB experts out there, please respond to me at
finkcr1@jhuapl.edu or to one of these newsgroups. Thanks.
Clay Fink
Technical Details
Message-ID:
<NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!gatech!udel!usenetShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!gatech!udel!usenet From: finkcr1@ptu-crf-pc.jhuapl.edu Newsgroups: comp.os.ms-windows.programmer.graphics,comp.lang.c++ Subject: Saving a DIB to a file Date: Fri, 19 Jan 96 07:35:46 PDT Organization: University of Delaware Message-ID: <NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu> NNTP-Posting-Host: ptu-crf-pc.jhuapl.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage