how to get Bitsperpixel from a bitmap

jason clark picture jason clark · Jul 14, 2009 · Viewed 19.1k times · Source

I have a 3rd party component which requires me to give it the bitsperpixel from a bitmap.

What's the best way to get "bits per pixel"?

My starting point is the following blank method:-

public int GetBitsPerPixelMethod( system.drawing.bitmap bitmap )
{
   //return BitsPerPixel;
}

Answer

CodeAndCats picture CodeAndCats · Sep 30, 2009

Rather than creating your own function, I'd suggest using this existing function in the framework:

Image.GetPixelFormatSize(bitmap.PixelFormat)