Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取位图的颜色深度_C#_Image_Winforms_Bit Depth - Fatal编程技术网

C# 获取位图的颜色深度

C# 获取位图的颜色深度,c#,image,winforms,bit-depth,C#,Image,Winforms,Bit Depth,我想用c#获取图像文件的位深度(和颜色空间) 这是我的护照。使用windows资源管理器的属性,我验证了它们的位深度(8、16、24、48、96) BitmapImage.Format.BitsPerPixel 对于8位灰度,返回8,但对于所有其他类型,返回32 Image.pixel格式 适用于除32位浮点映像以外的所有映像,在该映像中抛出System.OutOfMemoryException Image.PropertyItems 建议使用PropertyItems属性 与上面的示例类似,但

我想用c#获取图像文件的位深度(和颜色空间)

这是我的护照。使用windows资源管理器的属性,我验证了它们的位深度(8、16、24、48、96)

BitmapImage.Format.BitsPerPixel 对于8位灰度,返回8,但对于所有其他类型,返回32

Image.pixel格式 适用于除32位浮点映像以外的所有映像,在该映像中抛出
System.OutOfMemoryException

Image.PropertyItems 建议使用PropertyItems属性

与上面的示例类似,但会引发32位图像的异常


这建议使用Windows API代码包。但我更愿意使用原生c#特性



是否有一种内置的方法来确定图像的位深度,它使用1、8、16、24、48、96位?

它抛出
OutOfMemoryException
,因为GDI+不支持32位浮点位图(遗憾的是,“内存不足”是GDI给出的一般错误号)。如果您需要支持它们,您将需要一个第三方库。@Luaan这是否意味着不完全支持32位?因为它们可以转换为位图,请参见我的第一个问题:这不是转换为
位图
,而是转换为
位图源代码
。这是完全不同的。转换/解码,但不保留在32位flp中。。测试文件链接已断开。通常,System.Drawing命名空间不可能断开此链接。NET附带的编解码器旨在创建易于快速处理和显示的内存位图,如果需要,它们将从文件中的像素格式转换为该格式以实现该目标。要做到这一点,你需要一个图书馆,如果你想要全部的话,那就相当困难了。主要工具是千磅大猩猩。
var source = new BitmapImage(new Uri(path));
int bitsPerPixel = source.Format.BitsPerPixel;
Image img = Image.FromFile(path);
string pixelFormat = img.PixelFormat.ToString();
ShellObject so = ShellObject.FromParsingName(filename)
int bitdepth = convert.ToInt32(so.Properties.GetProperty(SystemProperties.System.Image.Bitdepth).ValueAsObject);