Re: Writing to 8-bit memory bitmap



I considered that, but the CreateDIBSection documentation is confusing. On the one hand,
it says

ppvBits [out] pointer to a variable that receives a pointer to the location of the DIB bit
values

which is what I would need, but then it says

hSection [in] ...if hSection is NULL, the system allocates memory for the DIB. In this
case, ... an application cannot later obtain a handle to this memory.

This seems to suggest that you cannot get hold of the memory that is used for the bitmap,
and at 5am I did not have enough functioning neurons to figure out exactly how to resolve
these two apparently conflicting statements. I have no idea why I would want a handle
when I clearly specified as NULL, or why I should be surprised if, later, I ask for it and
it tells me exactly that the handle I provided was NULL, but what does this have to do
with the ppvBits parameter? The documentation seems to be going out of its way to tell me
about something I clearly do not care about, and consequently the documentation doesn't
make any sense. If I give a handle of NULL for a file-mapping section, why would I have
the slightest interest in getting this NULL handle back? Why would I even care about
getting a handle to something that clearly is irrelevant?

Could it be that CreateDIBSection, if I give a NULL handle, creates a file-mapping object
for me? If so, why should I care about how it is implemented, and why does the
documentation suggest that I even *might* be interested in something that is a mere
implementation detail, completely beyond my concern?

That's when I posted the request and went to bed...
joe

On Thu, 31 Jul 2008 09:07:34 -0400, "Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx>
wrote:

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

.



Relevant Pages

  • Re: Writing to 8-bit memory bitmap
    ... ppvBits is a pointer to the memory that was allocated with CreateDIBSection. ... You may cache this pointer and use it later. ... for the bitmap ... CreateDIBSection allocates memory using file mapping. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Creating lots of bitmaps
    ... it is totally fragmenting memory. ... that can be used for a bitmap of any size. ... CreateDIBSection allows you to pass the handle to a memory mapped file that ... memory mapped file file will be overwritten with the new data. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Creating lots of bitmaps
    ... it is totally fragmenting memory. ... CreateDIBSection allows you to pass the handle to a memory mapped file that is used to store the pixel bits. ... You can re-use that file for a new bitmap when it is no longer needed for an old bitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • CreateDIBSection and non-memory device contexts
    ... Every code example of CreateDIBSection I have looked at selects the ... bitmap into a memory DC and then bitblts from the memory dc to the ... there anything wrong with selecting a bitmap into a screen DC ... the function uses this device context's logical palette to initialize ...
    (microsoft.public.win32.programmer.gdi)
  • Re: memory leak
    ... ArgumentException on Full Framework) when I have a ton of virtual memory ... "new Bitmap" line. ... Dispose is not a required call - it is optional. ... you are done with those resources. ...
    (microsoft.public.dotnet.framework.compactframework)

Loading