GDIPlus Question

VB_Alien
02-07-2005, 03:39 PM
I made this program using gdiplus that among other things, reads the pixel format. Its working but i dont understand what it means. I put the pixel format results in a label and it come out to being 137224 for a 800x600 jpg file. Do these numbers means something to anyone?

OnErr0r
02-07-2005, 06:15 PM
The PixelFormat is a bitmask of various formats. In order to understand it's true meaning better, first convert it to hex:

137224 decimal = &H21808 = PixelFormat24bppRGB

// In-memory pixel data formats:
// bits 0-7 = format index
// bits 8-15 = pixel size (in bits)
// bits 16-23 = flags
// bits 24-31 = reserved

&H20000 = PixelFormats.PixelFormatGDI ' Is a GDI-supported format
&H01800 = 24 * 256 aka 24 << 8
&H00008
=
&H21808


Or in other words:
PixelFormat24bppRGB = (PixelFormatGDI Or (24 * 256) Or 8)

VB_Alien
02-07-2005, 08:51 PM
I kind of see what your code is showing but i'm still confused. I got the hex value by coding it this way:

PixelFormat = Hex(GDIPicture.PixelFormat) and i got 21808.

PixelFomat being a long variable and GDIPicture is a class module i threw all my GDIPlus code in. Anyway, in that class module i have an Enum called PixelFormats and this is the pixelformat i assume you came up with.

PixelFormat24bppRGB = &H1808 Or PixelFormatGDI

I'm not sure where the 2 comes from in that number but i'm guessing it means its a GDI acceptable enum.

Now the question is - is there a way to code it so that i can display something in a label control that is easy to understand, what the pixelformat is? Something like " 16 million colors " just from getting the accual pixelformat. People wouldnt understand a number in a label.

I hope you understand what i'm trying to ask you. I know i botched it up.

OnErr0r
02-07-2005, 09:07 PM
PixelFormat24bppRGB = &H1808 Or PixelFormatGDI

I'm not sure where the 2 comes from in that number but i'm guessing it means its a GDI acceptable enum.


The 2 is part of the number 24, which stands for 24 bit.

PixelFormat 24 Bits Per Pixel RGB (Red, Green, Blue)

In order to get something meaningful back from that combination of bits, you have to bitmask and shift:

// bits 0-7 = format index
// bits 8-15 = pixel size (in bits)
// bits 16-23 = flags


Dim lFormat as long

FormatIndex = lFormat And 255
PixelSize = (lFormat And &HFF00&) \ 256
Flags = (lFormat And &HFF000) \ 65536


Here is all the pertainent information:


#define PixelFormatIndexed 0x00010000 // Indexes into a palette
#define PixelFormatGDI 0x00020000 // Is a GDI-supported format
#define PixelFormatAlpha 0x00040000 // Has an alpha component
#define PixelFormatPAlpha 0x00080000 // Pre-multiplied alpha
#define PixelFormatExtended 0x00100000 // Extended color 16 bits/channel
#define PixelFormatCanonical 0x00200000

#define PixelFormatUndefined 0
#define PixelFormatDontCare 0

#define PixelFormat1bppIndexed (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI)
#define PixelFormat4bppIndexed (2 | ( 4 << 8) | PixelFormatIndexed | PixelFormatGDI)
#define PixelFormat8bppIndexed (3 | ( 8 << 8) | PixelFormatIndexed | PixelFormatGDI)
#define PixelFormat16bppGrayScale (4 | (16 << 8) | PixelFormatExtended)
#define PixelFormat16bppRGB555 (5 | (16 << 8) | PixelFormatGDI)
#define PixelFormat16bppRGB565 (6 | (16 << 8) | PixelFormatGDI)
#define PixelFormat16bppARGB1555 (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI)
#define PixelFormat24bppRGB (8 | (24 << 8) | PixelFormatGDI)
#define PixelFormat32bppRGB (9 | (32 << 8) | PixelFormatGDI)
#define PixelFormat32bppARGB (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)
#define PixelFormat32bppPARGB (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI)
#define PixelFormat48bppRGB (12 | (48 << 8) | PixelFormatExtended)
#define PixelFormat64bppARGB (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended)
#define PixelFormat64bppPARGB (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended)
#define PixelFormatMax 15

OnErr0r
02-07-2005, 09:11 PM
Oh, and once you have the Flags value, you'll need to Binary And with the first six values starting with PixelFormatIndexed. That will tell you which of those are set.

For instance:

if (Flags And PixelFormatIndexed) = PixelFormatIndexed Then ' It is an indexed format, append the desired string to your string compilation now

VB_Alien
02-07-2005, 11:17 PM
I'm not sure if i'm doing this right so i'll post my code and if you dont mind, could you tell me if i'm doing it right?

Private PixelFormat as long
Private FormatIndex As Long
Private PixelSize As Long
Private Flags As Long

First off i'm not sure if i'm suppose to use the hex number or the whole number. If i use the hex number like this the output is rather big.

PixelFormat = Hex(GDIPicture.PixelFormat)

FormatIndex = PixelFormat And 255 I get 48
PixelSize = (PixelFormat And &HFF00&) \ 256 I get 85
Flags = (PixelFormat And &HFF000) \ 65536 I get 0

If i use the whole number the output is better bet i dont think its right.

PixelFormat = GDIPicture.PixelFormat

FormatIndex = PixelFormat And 255 I get 8
PixelSize = (PixelFormat And &HFF00&) \ 256 I get 24
Flags = (PixelFormat And &HFF000) \ 65536 I get 2

If those 3 number i got are suppose to be within the range of numbers you posted then i'm not doing something right.

// bits 0-7 = format index
// bits 8-15 = pixel size (in bits)
// bits 16-23 = flags

OnErr0r
02-08-2005, 01:06 AM
8 is correct for the format index
24 is correct for the pixel size in bits

Flags doesn't need to be right shifted, so you can drop the \ 65536. Then 2 will become &H20000 or PixelFormatGDI.

The operations are to be performed on a long containing the PixelFormat, not on a hex string. The Hex$ function returns a string.

VB_Alien
02-08-2005, 07:22 AM
Sorry to keep bugging you about this but i'm trying to wrap my head around this.

So are you saying instead of doing this:
Flags = (PixelFormat And &HFF000) \ 65536

I should be doing this:
Flags = (PixelFormat And &HFF000)

If i do that latter one Flags = 135168

This is confusing.

OnErr0r
02-08-2005, 09:35 AM
oops, I missed one zero in my mask.

Flags = (PixelFormat And &HFF0000)

VB_Alien
02-08-2005, 10:12 AM
Now i come up with 131072. Is this correct?

Are you saying the last number, witch is 2, will become &H20000 or PixelFormatGDI?

OnErr0r
02-08-2005, 10:17 AM
Look at the returned values in Hex, since that is what the constants are, it will make a LOT more sense. :)

131072 = &H20000

VB_Alien
02-08-2005, 10:51 AM
Yeah. That sure did help. I think i'm beginning to understand it now.

Thanks alot for all the help. I do appreciate it.....

VB_Alien
02-08-2005, 05:31 PM
Apon further loading of different graphic formats, it would appear GDIPlus doesnt support some common formats. Either that or i dont have all the enum values for PixelFormats.

It loads and displays jpg info just fine but when i try most bmp's and all gif's and png's, i get numbers that arent supported.

This is for all of them except jpg:

PixelFormat = GDIPicture.PixelFormat

PixelFormat Hexed = 30803
Flags = 196608
Flags Hexed = 30000
PixelSize = 8
FormatIndex = 3

I dont have any PixelFormat enums that equal 3000.
Mine are:

10000 = PixelFormatIndexed
20000 = PixelFormatGDI
40000 = PixelFormatAlpha
80000 = PixelFormatPAlpha
100000 = PixelFormatExtended
200000 = PixelFormatCanonical

Is there some sort of trick involved here to some how get the correct data or am i missing something in my GDIPlus Class Module?

OnErr0r
02-08-2005, 06:26 PM
10000 = PixelFormatIndexed
Or (Binary)
20000 = PixelFormatGDI
=
30000

You might want to take a few minutes to read my Bits, Bytes and Bases tutorial in the Tutor's Corner. :)

VB_Alien
02-08-2005, 07:13 PM
I guess i forgot about that. I'll read your tut. Thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum