Thread View: comp.os.ms-windows.programmer.graphics
2 messages
2 total messages
Started by finkcr1
Fri, 19 Jan 1996 14:35
Saving a DIB to a file
Author: 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
Re: Saving a DIB to a file
Author: Chris Marriott
Date: Fri, 19 Jan 1996 19:12
Date: Fri, 19 Jan 1996 19:12
44 lines
2328 bytes
2328 bytes
In article <NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu>
finkcr1@ptu-crf-pc.jhuapl.edu writes:
>
>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
The problem here is your "CreateCompatibleBitmap" call. You need to create
a bitmap that's compatible with the SCREEN dc, not the MEMORY one.
Change your code to say:
CDC *pDC = GetDC();
memDC.CreateCompatibleDC(pDC);
bm.CreateCompatibleBitmap( pDC, ..... );
and it will work fine.
Chris
--
--------------------------------------------------------------------------
Chris Marriott, Warrington, UK | Author of SkyMap v3 award-winning
chris@chrism.demon.co.uk | shareware Win31/Win95 planetarium.
For full info, see http://www.execpc.com/~skymap
Author member of Association of Shareware Professionals (ASP)
--------------------------------------------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads