Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get Bitsperpixel from a bitmap

Tags:

c#

drawing

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;
}
like image 342
jason clark Avatar asked Jul 14 '09 17:07

jason clark


3 Answers

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

Image.GetPixelFormatSize(bitmap.PixelFormat)
like image 184
CodeAndCats Avatar answered Nov 20 '22 08:11

CodeAndCats


var source = new BitmapImage(new System.Uri(pathToImageFile));
int bitsPerPixel = source.Format.BitsPerPixel;

The code above requires at least .NET 3.0

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx

like image 8
Matthew Johnson Avatar answered Nov 20 '22 07:11

Matthew Johnson


What about Image.GetPixelFormatSize()?

like image 4
Scott Avatar answered Nov 20 '22 07:11

Scott