By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Find out how many colors in a Bitmap

P: n/a
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?
Aug 2 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I meant Windows Struct not API

>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?

Aug 2 '07 #2

P: n/a
On 2 Ago, 18:04, " active" <activeNOS...@a-znet.comwrote:
I meant Windows Struct not API
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?

Have you taken a look at :

System.Drawing.Imaging.PixelFormat
System.Drawing.Imaging.ColorPalette

?

T

Aug 2 '07 #3

P: n/a
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
"to**************@uniroma1.it" <To**************@gmail.comwrote in message
news:11*********************@x40g2000prg.googlegro ups.com...
On 2 Ago, 18:04, " active" <activeNOS...@a-znet.comwrote:
>I meant Windows Struct not API
>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?


Have you taken a look at :

System.Drawing.Imaging.PixelFormat
System.Drawing.Imaging.ColorPalette

?

T

Aug 2 '07 #4

P: n/a
On 2 Ago, 21:42, " active" <activeNOS...@a-znet.comwrote:
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

"tommaso.gasta...@uniroma1.it" <Tommaso.Gasta...@gmail.comwrote in message

news:11*********************@x40g2000prg.googlegro ups.com...
On 2 Ago, 18:04, " active" <activeNOS...@a-znet.comwrote:
I meant Windows Struct not API
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?
Have you taken a look at :
System.Drawing.Imaging.PixelFormat
System.Drawing.Imaging.ColorPalette
?
T- Nascondi testo tra virgolette -

- 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

Aug 3 '07 #5

P: n/a

>
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




Aug 5 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.