Re: Writing to 8-bit memory bitmap
- From: "Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 09:07:34 -0400
I'd prefer to write directly to the 8-bit bitmap than have to convert a
24-bit bitmap to 8
bits externally.
Create an empty 8bpp bitmap with CreateDIBSection and select it to a memory
device context.
You need to create a palette for the 8bpp bitmap and use SetDIBColorTable
before using any of the GDI drawing routines(e.g., BitBlt, etc.).
BitBlt and the like will do the color conversion for you, if necessary(i.e.,
32bpp, 16bpp, 24bpp drawing to 8bpp).
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:l2u2945bbi6hl73tt3deltq8r30kvijdc7@xxxxxxxxxx
Here's a problem I've been wrestling with for almost a day.
I need to have an 8-bit bitmap created for later processing. It would
seem obvious that
the right thing to do is to create an 8-bit bitmap, select it into a
memory DC, do the
drawing, and then write the bitmap out.
We should live so long that something this obvious should work correctly.
First, it appears that it is impossible to create a memory DC that has a
color depth other
than that of the display (even though the bitmap will never be written to
the display). If
I CreateCompatibleDC, then CreateBitmap of an 8-bit bitmap, and
SelectObject of the new
bitmap into the DC, it doesn't work (in spite of the documentation, that
states that a
memory DC takes on the color depth of the bitmap that is selected into
it...); the return
value from SelectObject is NULL (indicating failure) and
GetCurrentBitmap/GetBitmap
reveals that the current bitmap in the DC is the 1x1 monochrome bitmap (so
no selection
occurred).
But if I CreateCompatibleBitmap, the bitmap takes on 24-bit color depth,
which is
inconsitent with writing the bitmap to an AVI file (which is what I am
doing); there is no
installed codec on my system that can handle 24-bit format (I'm running
with WMP 11).
I'd prefer to write directly to the 8-bit bitmap than have to convert a
24-bit bitmap to 8
bits externally. The images are simple and use few colors, so I could do
it, but I keep
thinking I'm missing something by not being able to create a memory DC I
can write to
(there seems to be this horrible fixation that a memory DC needs to have
the same color
depth as the display, although I cannot fathom why, and there is
documentation that speaks
directly against this, but it is obviously lying)
joe
.
- Follow-Ups:
- Re: Writing to 8-bit memory bitmap
- From: Joseph M . Newcomer
- Re: Writing to 8-bit memory bitmap
- References:
- Writing to 8-bit memory bitmap
- From: Joseph M . Newcomer
- Writing to 8-bit memory bitmap
- Prev by Date: Problem with GDI and Aero
- Next by Date: Re: Problem with GDI and Aero
- Previous by thread: Writing to 8-bit memory bitmap
- Next by thread: Re: Writing to 8-bit memory bitmap
- Index(es):
Relevant Pages
|
Loading