Find out how many colors in a Bitmap

  • Thread starter Thread starter active
  • Start date Start date
A

active

I need to know how many colors in the color table are actually used.

Do I need to use Windows API?

I been searching the Bitmap doc and can't find a property that would help.

Is there a way other than Windows API to get that information?



Thanks


PS
If I type: Bitmap1.Entries.
Intelisense gives many options that do not appear as Bitmap.Entries
properties.
I assume those are general array properties and are not specific for
Bitmap.Entries.
Right?
 
System.Drawing.Imaging.PixelFormat
just tells max colors
System.Drawing.Imaging.ColorPalette
ColorPalette only has property Entries that might help but it is simply a
array of maxcolor size, or maybe it's always 256, I forgot. Anyone know?

Seems like it must know the colors used because if it writes a BMP file it
needs to write that value. Maybe it calculates it then? Anyone know?

From other post I've learned that what you see and what gets written may not
agree so maybe it does it calculates it then.

Thanks
 
System.Drawing.Imaging.PixelFormat
just tells max colors


ColorPalette only has property Entries that might help but it is simply a
array of maxcolor size, or maybe it's always 256, I forgot. Anyone know?

Seems like it must know the colors used because if it writes a BMP file it
needs to write that value. Maybe it calculates it then? Anyone know?

From other post I've learned that what you see and what gets written may not
agree so maybe it does it calculates it then.

Thanks







- Mostra testo tra virgolette -

If you need the *exact* number, I am afraid you have no choice but to
scan the bitmap (use c# and pointers) and count the distinct colors.


T
 
If you need the *exact* number, I am afraid you have no choice but to
scan the bitmap (use c# and pointers) and count the distinct colors.


T
I was thinking of BITMAPINFOHEADER

do you know the difference between BiClrUsed and BiClrImportant



What I want is, no mater how big the table is, I want to know how many
"useful" colors there are in it.

I've seen 256 color tables with BiCltUsed=16

And everything after the 16th color is junk.



If I have to scan the Bitmap data I can use

If biClrUsed > 0 Then

NColor = CInt(biClrUsed)

ElseIf biBitCount < 24 Then

NColor = 1 << biBitCount

Else

NColor = 0

End If

This seems to work.

But can't biBitCount be <24 when biClrUsed >0?





I was hoping for a bitmap "number used" property.







thanks
 
Back
Top