如何从一个位图得到Bitsperpixel [英] how to get Bitsperpixel from a bitmap
问题描述
我有要求我给它从位图的bitsperpixel一个第三方组件。
I have a 3rd party component which requires me to give it the bitsperpixel from a bitmap.
什么让每像素位数的最佳方法是什么?
whats the best way to get "bits per pixel"?
我有一个C#Windows应用程序,我的出发点是在下面的空格方法: -
I have a c# windows app and my starting point is the following blank method:-
public int GetBitsPerPixelMethod( system.drawing.bitmap bitmap )
{
//return BitsPerPixel;
}
目前我没有安装,如DirectX或任何东西任何花哨的图书馆的的momement - 但我开放的建议。
At the momement I dont have any fancy librarys installed such as directx or anything - but am open to suggestions.
感谢,
杰森
推荐答案
使用像素格式财产,这返回的PixelFormat枚举它的值可以是FE Format24bppRgb
,这显然是每像素24位,所以你应该能够做这样的事:
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;
}
这篇关于如何从一个位图得到Bitsperpixel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!