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

时间:2015-06-04 10:49:41

标签: bitmap xamarin.android android-bitmap

在.NET中,一种检查Bitmap图像的bitdepth的方法是使用Bitmap类,如下所示:

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的Mono(xamarin项目)的等效函数,该函数返回Bitmap文件的bitdepth,但Adroid.Graphics命名空间中的Bitmap类却没那么有用 - 或者可能只是太勉强对我来说。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

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

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