What is a Bitmap

  • Thread starter Thread starter \Frank\
  • Start date Start date
F

\Frank\

I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one
that, for example, comes from the clipboard with CF_BITMAP.

I'm guessing that a CompatableBitmap is an array of indices that point to
the colors in a Palette of the display driver.

So if I get a bitmap via CF_BITMAP I need to also get a Palette off the
clipboard and realize it then display the bitmap.

I believe "Realize it" means to put it into the display driver.


Is any of the above correct?

Can you say it better - I'm really guessing at the terminology.


Thanx for any help
 
So if I get a bitmap via CF_BITMAP I need to also get a Palette off the
clipboard and realize it then display the bitmap.

The CF_BITMAP represents an HBITMAP handle to a GDI Bitmap.

That bitmap handle can be a DIB or a DDB(i.e., Device Independent or Device
Dependent ).

If the bitmap is indexed, you need to retrieve the CF_PALETTE from the
clipboard.

The CF_PALETTE is a handle to a GDI Palette.

You also have the option to avoid retrieving the palette of an indexed
bitmap by
requesting a CF_DIB from the clipboard. The CF_DIB is a Global Memory
Handle
that represents a Device Independent Bitmap which alread includes the color
table, if present.

The clipboard always synthesizes this format regardless if the original
application placed the CF_DIB
on the clipboard.
 
Paint puts both "Bitmap" and "DIB Bitmap" on the clipboard.
At least WordPad "Paste Special" shows both after a Paint "Copy"
So I assume they are different things.

I see from what you said below that a CF-BITMAP can represent a handle to a
DIB so in that case I guess they'd be the same.

And you also said that a DIB includes a color table.

So, can I conclude that one difference between a DIB and a DDB is that the
DDB does not include a color table.

If you wanted to use a DDB you need to know the related color table

Also, even though WordPad shows both "Bitmap" and "DIB Bitmap" the
dataobject (DataO.GetFormats(False)) shows only the DIB. Why do you think
that is?

So, when you get a handle from the clipboard you don't know if it points to
a DDB or a DIB. Is that a problem?


Thanx


I'm going to search for DDB to see if I can learn more that way.
 
So, can I conclude that one difference between a DIB and a DDB is that the
DDB does not include a color table.

A DDB is optimized for your Display Driver's current bit depth.

If that depth is 32bpp or 16bpp, then no palette is necessary. If your
Display's depth is 8bpp then a palette is necessary.
So, when you get a handle from the clipboard you don't know if it points
to a DDB or a DIB. Is that a problem?

It is easy to test what the HBITMAP represents. Use GDI GetObject with
DIBSECTION.

If the return is sizeof(DIBSECTION) then it is a DIB. If not it is a DDB.
Also, even though WordPad shows both "Bitmap" and "DIB Bitmap" the
dataobject (DataO.GetFormats(False)) shows only the DIB. Why do you think
that is?

The CF_BITMAP and CF_DIB formats are synthesized by the clipboard when the
application that
places one format but not the other on the clipboard.

You can always retrieve the synthesized formats. Use GetFormats(True).
 
If you can, one more question.

I found CreateCompatibleBitmap which can be used to create a DDB.
And CreateCompatibleDC which can be used to write on it.
I know this is an academic question but where is the color table (if there
is one).
I'd guess it's in the CompatibleDC.

Thanks
 
I found CreateCompatibleBitmap which can be used to create a DDB.
And CreateCompatibleDC which can be used to write on it.
I know this is an academic question but where is the color table (if there
is one).

CreateCompatibleBitmap creates an empty bitmap of the width and height of
your choice optimized for the current Display's bit depth.

If your Display is set for 16bpp or 32bpp, then there is no color table.
I'd guess it's in the CompatibleDC.

It contains whatever palette that was selected into it.
GetCurrentPalette will provide you with the palette currently selected into
the device context.

If your display depth is 8bpp, then you must create, select and realize a
palette before you can render to the empty indexed bitmap.
 
Great answers.

Thanx

Michael Phillips said:
CreateCompatibleBitmap creates an empty bitmap of the width and height of
your choice optimized for the current Display's bit depth.

If your Display is set for 16bpp or 32bpp, then there is no color table.


It contains whatever palette that was selected into it.
GetCurrentPalette will provide you with the palette currently selected
into the device context.

If your display depth is 8bpp, then you must create, select and realize a
palette before you can render to the empty indexed bitmap.
 
Back
Top