开发者

How can i know what is the bitmap color size of each pixel?

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;


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜