Article View: comp.os.ms-windows.programmer.graphics
Article #13Re: Saving a DIB to a file
From: 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)
--------------------------------------------------------------------------
Technical Details
Message-ID:
<822078728snz@chrism.demon.co.uk>Path:
arc1-ca.pugleaf.net!mail2news.demon.co.uk!chrism.demon.co.ukReferences:
<NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!chrism.demon.co.uk From: Chris Marriott <chris@chrism.demon.co.uk> Newsgroups: comp.os.ms-windows.programmer.graphics,comp.lang.c++ Subject: Re: Saving a DIB to a file Date: Fri, 19 Jan 96 19:12:08 GMT Organization: None Message-ID: <822078728snz@chrism.demon.co.uk> References: <NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu> Reply-To: chris@chrism.demon.co.uk X-NNTP-Posting-Host: chrism.demon.co.uk X-Newsreader: Demon Internet Simple News v1.30 X-Mail2News-Path: chrism.demon.co.uk