Color Count of image in an image (or picturebox) control

Color Count of image in an image (or picturebox) control

Post by Greg Jone » Fri, 06 Oct 2000 04:00:00


Greetings,
I would appreciate any assistance that can be offered towards a VB6
function/routine, that will give the unique color count of an image
displayed preferrably in an image control, and optionally in picturebox
control using VB6.

Thank you for your assistance,

Greg Jones


 
 
 

Color Count of image in an image (or picturebox) control

Post by Richard Maso » Sat, 07 Oct 2000 04:00:00




Quote:>I would appreciate any assistance that can be offered towards a VB6
>function/routine, that will give the unique color count of an image
>displayed preferrably in an image control, and optionally in picturebox
>control using VB6.

8 bit or 24 bit desktop?

--
Richard Mason

 
 
 

Color Count of image in an image (or picturebox) control

Post by Greg Jone » Sat, 07 Oct 2000 04:00:00


Hello Mr. Mason,

Having not known this would make a difference...

errr... Both? Always trying to be thorough, and keeping all contingencies
covered. (obviously I would have to determine endusers desktop bitdepth, and
proceed accordingly (this in itself should be easily done)
I have tried several routines, using BITMAPFILEHEADER, BITMAPINFOHEADER etc
to extract information, however it hasnt appeared to report # of colors (in
8bit graphic) accurately (always says 256 or 16 in a 4 bit graphic,
regardless of actual number "used").  And it does not report that
information at all for a 24 bit graphic... ive been trying!!! :) (could any
of this because of my desktop bitdepth?)

However, it is most likely, that endusers of my game program, will be
running 16-24bit desktops.
Most gamers I know, left 256 colors behind long ago... :) So as far as
desktop bitdepth, I can probably count on my endusers to be 16-32bit depth
(I assume these are programmatically the same as 24bit... hopefully im not
assuming too much) (my videocard has 16bit and 32 bit, no 24 bit.. are these
pretty much the same overall?)

Any assistance is greatly appreciated.

Thank you,
Greg Jones




> >I would appreciate any assistance that can be offered towards a VB6
> >function/routine, that will give the unique color count of an image
> >displayed preferrably in an image control, and optionally in picturebox
> >control using VB6.

> 8 bit or 24 bit desktop?

> --
> Richard Mason

 
 
 

Color Count of image in an image (or picturebox) control

Post by Richard Maso » Sun, 08 Oct 2000 04:00:00




Quote:>errr... Both? Always trying to be thorough, and keeping all contingencies
>covered. (obviously I would have to determine endusers desktop bitdepth, and
>proceed accordingly (this in itself should be easily done)
>I have tried several routines, using BITMAPFILEHEADER, BITMAPINFOHEADER etc
>to extract information, however it hasnt appeared to report # of colors (in
>8bit graphic) accurately (always says 256 or 16 in a 4 bit graphic,
>regardless of actual number "used").  And it does not report that
>information at all for a 24 bit graphic... ive been trying!!! :) (could any
>of this because of my desktop bitdepth?)

>However, it is most likely, that endusers of my game program, will be
>running 16-24bit desktops.
>Most gamers I know, left 256 colors behind long ago... :) So as far as
>desktop bitdepth, I can probably count on my endusers to be 16-32bit depth
>(I assume these are programmatically the same as 24bit... hopefully im not
>assuming too much) (my videocard has 16bit and 32 bit, no 24 bit.. are these
>pretty much the same overall?)

Forget 8 bit then.

16 bit Desktop
Maximum number of unique colors that can be displayed is 65,536

24 bit Desktop
Maximum number of unique colors that can be displayed is 16,777,216 and
that is the maximum number you can ever display.

32 bit Desktop
Maximum number of unique colors same as for 24 bit desktop.
The 32 bit is for speeding up color display

For a file on disk nothing within the file will tell you how many
_unique_ colors the image actually uses. The biBitCount value of the
BITMAPINFOHEADER says what bit depth the file was created with, but you
can have a 24 bit .bmp file with only one color.

I suspect is quite common to have video cards with no 24 bit setting.
When a bmp is loaded into a PictureBox at design time, or with
LoadPicture, the loaded bitmap is displayed at the resolution set by the
Desktop.

To count the number of unique colors in a displayed bitmap I'm afraid
you have to work through every single color in the bitmap, and keep a
running total of colors that only occur once. One can do this for the
same bitmap in a file but the two answers won't necessarily be the same.
For example a 24 bit .bmp file that has 30,121 unique colors only has
13,592 unique colors when displayed on a 16 bit Desktop.

--
Richard Mason

 
 
 

Color Count of image in an image (or picturebox) control

Post by Greg Jone » Sun, 08 Oct 2000 04:00:00


Thank you for explaining.  Youve been very helpful.
I know how to do what you mentioned (going through each color, etc)
Not sure having that information is worth the trouble.

Thanks, and happy computing,

Greg




> >errr... Both? Always trying to be thorough, and keeping all contingencies
> >covered. (obviously I would have to determine endusers desktop bitdepth, and
> >proceed accordingly (this in itself should be easily done)
> >I have tried several routines, using BITMAPFILEHEADER, BITMAPINFOHEADER etc
> >to extract information, however it hasnt appeared to report # of colors (in
> >8bit graphic) accurately (always says 256 or 16 in a 4 bit graphic,
> >regardless of actual number "used").  And it does not report that
> >information at all for a 24 bit graphic... ive been trying!!! :) (could any
> >of this because of my desktop bitdepth?)

> >However, it is most likely, that endusers of my game program, will be
> >running 16-24bit desktops.
> >Most gamers I know, left 256 colors behind long ago... :) So as far as
> >desktop bitdepth, I can probably count on my endusers to be 16-32bit depth
> >(I assume these are programmatically the same as 24bit... hopefully im not
> >assuming too much) (my videocard has 16bit and 32 bit, no 24 bit.. are these
> >pretty much the same overall?)

> Forget 8 bit then.

> 16 bit Desktop
> Maximum number of unique colors that can be displayed is 65,536

> 24 bit Desktop
> Maximum number of unique colors that can be displayed is 16,777,216 and
> that is the maximum number you can ever display.

> 32 bit Desktop
> Maximum number of unique colors same as for 24 bit desktop.
> The 32 bit is for speeding up color display

> For a file on disk nothing within the file will tell you how many
> _unique_ colors the image actually uses. The biBitCount value of the
> BITMAPINFOHEADER says what bit depth the file was created with, but you
> can have a 24 bit .bmp file with only one color.

> I suspect is quite common to have video cards with no 24 bit setting.
> When a bmp is loaded into a PictureBox at design time, or with
> LoadPicture, the loaded bitmap is displayed at the resolution set by the
> Desktop.

> To count the number of unique colors in a displayed bitmap I'm afraid
> you have to work through every single color in the bitmap, and keep a
> running total of colors that only occur once. One can do this for the
> same bitmap in a file but the two answers won't necessarily be the same.
> For example a 24 bit .bmp file that has 30,121 unique colors only has
> 13,592 unique colors when displayed on a 16 bit Desktop.

> --
> Richard Mason

--
Greg Jones

(remove the "1" from email if you need to email me)

 
 
 

1. Array into PictureBox into Image-Control

Hello,

I am still looking for a solution of the following problem: I have a
bitmap information in a byte-array myPicBytes().
I want to load this information into an Image-Control. Since API seems
to work only with picturebox-COntrols,
I do the data transfer from the array into a picturebox and from there
into the image. To run SetDIBits
PictureBox.Picture.handle must be valid (<>0), which is zero for an
empty PictureBox (even if Autoredraw=true). Therefor I
have pasted a small black bitmap into the picturebox just to make the
handle valid. Running this code works fine, except
for the following: If the bitmap in the arry is small, I see the rest of
the black bitmap in my Image-Control (setting the
original bitmap to 1 pixel would reduce this problem) - but, if the new
bitmap is larger then the original one,
after the transfer into the image control, from the new bitmap you only
see a part, with the size of the original black one.
Since I know the size of the new bitmap (width, height) I wonder if
there is a way to first adjust the black bitmap
inside the picturebox to a new size (to fit exactly) and then do
SetDIBits to change the picture and then hopefully
copy the complete picture information into the image-Control.
It seem, that if you use Paintpicture to draw the picture first into a
second picturebox, draws the picture correct, but if
I say Image1.picture=picture2.picture, nothing is transferred - as if
Picture2.picture would not exist.

Or is there a way to load Image-Controls via API (I want to use the
STRECH-Property)

Sub ArrayAPIPicture(myImage, myPicBytes() As Byte)

Dim l As Long
Dim BI4 As BITMAPINFO4

Load frmDBpicture
frmDBpicture.Show
Call CopyMemory(BI4, myPicBytes(14), Len(BI4))  'load Infoheader from
the bitmap-array
l = SetDIBits4(frmDBpicture.DBpicture.hdc,
frmDBpicture.DBpicture.Picture.handle, 0, BI4.bmiHeader.biHeight,
myPicBytes(BMPH.biOffset), BI4, DIB_RGB_COLORS)

myImage.Picture = frmDBpicture.DBpicture.Picture
Unload frmDBpicture
End Sub

2. Subject: Re: DetermRe: Determining vertex order (counterclockwise vs. clockwise)

3. : Picturebox / Image control

4. help with sin, cos, tan...

5. Printing Image of all controls in picture box to 2nd picturebox

6. Evaluating Planar Cubic Curves

7. Count the colors used in 24-bit images?

8. A minor problem with POVWin3s editor....

9. Counting colors in 24 bit image

10. Find images count in a bigger image...

11. Creating 256-color image from 24-bit color image in ImageMagick

12. How can i control num of colors of image in ImageList

13. Limiting the Image control to 256 colors