how to get Bitsperpixel from a bitmap

后端 未结 6 1940
心在旅途
心在旅途 2021-02-18 12:41

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 th

6条回答
  •  囚心锁ツ
    2021-02-18 13:34

    Use the Pixelformat property, this returns a Pixelformat enumeration which can have values like f.e. Format24bppRgb, which obviously is 24 bits per pixel, so you should be able to do something like this:

    switch(Pixelformat)       
      {
         ...
         case Format8bppIndexed:
            BitsPerPixel = 8;
            break;
         case Format24bppRgb:
            BitsPerPixel = 24;
            break;
         case Format32bppArgb:
         case Format32bppPArgb:
         ...
            BitsPerPixel = 32;
            break;
         default:
            BitsPerPixel = 0;
            break;      
     }
    

提交回复
热议问题