Reputation: 9926
I have some bitmap. I know that the bitmap format is PixelFormat.FormatXXXXXXbppRgb => but i want dynamically to calculate the size of each pixel.
For example => if the bitmap pixel format is Format24bppRgb i want to calculate that the R/G/B range is between 0 to 255.
So, i don't know how to get the information that in case of Format24bppRgb the R/G/B bit size is 3. or that in the format is Format32bppRgb that the R/G/B bit size is 4.
P.S: i don't want to use the code
BitmapData bmDateFrame = bitmap.LockBits(....)
Int32 picPixelBit = bmDateFrame.Stride / bitmap.Width;
Upvotes: 1
Views: 165
Reputation: 117230
It seems the 2nd byte (LSB) of the PixelFormat
value indicates that.
Doing something like this should work:
var somepixelformat = ...;
var colorsizeinbits = (((int)somepixelformat) >> 8) & 0xff;
Upvotes: 1