如何在 Mono For Android 上获取位图的位深度

How to get Bit Depth of a Bitmap on Mono For Android

在 .NET 中,检查位图图像位深度的一种方法是使用位图 class,如下所示:

switch (bitmap.PixelFormat) {
                case System.Drawing.Imaging.PixelFormat.Format1bppIndexed: return 1;
                case System.Drawing.Imaging.PixelFormat.Format4bppIndexed: return 4;
                case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: return 8;
                case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555:  
                case System.Drawing.Imaging.PixelFormat.Format16bppGrayScale:
                case System.Drawing.Imaging.PixelFormat.Format16bppRgb555:
                case System.Drawing.Imaging.PixelFormat.Format16bppRgb565: return 16;
                case System.Drawing.Imaging.PixelFormat.Format24bppRgb: return 24;
                case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
                case System.Drawing.Imaging.PixelFormat.Format32bppPArgb:
                case System.Drawing.Imaging.PixelFormat.Format32bppRgb: return 32;
                case System.Drawing.Imaging.PixelFormat.Format48bppRgb: return 48;
                case System.Drawing.Imaging.PixelFormat.Format64bppArgb:
                case System.Drawing.Imaging.PixelFormat.Format64bppPArgb: return 64;
}

我正在尝试为 Android(xamarin 项目)编写一个针对 Mono 的等效函数,returns 我是位图文件的位深度,但位图 class 在 Adroid.Graphics 命名空间,帮助不大 - 或者可能对我来说太陌生了。谁能帮忙?

您可以从 Adroid.Graphics.Bitmap.Config 属性 获得位图深度:

Bitmap.Config ARGB_4444 16 
Bitmap.Config ARGB_8888 32 
Bitmap.Config RGB_565 16  R5 G6 B5 ,no ALPHA