一个更好的PixelFormat.ToString输出

时间:2012-12-11 18:24:57

标签: c# winforms image system.drawing pixelformat

System.Drawing.Imaging命名空间中的PixelFormat枚举具有 Format32bppArgb Format8bppIndexed 等成员,在调用其 ToString <时会显示/ em>方法。

您是否知道将PixelFormat值转换为更适合在图形程序中显示的字符串的内置或其他方法,例如 24 BPP 24bpp

1 个答案:

答案 0 :(得分:3)

尝试类似这种扩展方法的东西我很快就聚集在一起:

public static string ToFancyString(this PixelFormat format)
{
    switch (format)
    {
        case PixelFormat.Format16bppArgb1555:
            return "16bpp ARGB";
        case PixelFormat.Format16bppGrayScale:
            return "16bpp Gray";
        case PixelFormat.Format16bppRgb555:
            return "16bpp RGB";
        case PixelFormat.Format16bppRgb565:
            return "16bpp RGB";
        case PixelFormat.Format1bppIndexed:
            return "1bpp Indexed";
        case PixelFormat.Format24bppRgb:
            return "24bpp RGB";
        case PixelFormat.Format32bppArgb:
            return "32bpp ARGB";
        case PixelFormat.Format32bppPArgb:
            return "32bpp Premultiplied ARGB";
        case PixelFormat.Format32bppRgb:
            return "32bpp RGB";
        case PixelFormat.Format48bppRgb:
            return "48bpp RGB";
        case PixelFormat.Format4bppIndexed:
            return "4bpp Indexed";
        case PixelFormat.Format64bppArgb:
            return "64bpp ARGB";
        case PixelFormat.Format64bppPArgb:
            return "64bpp Premultiplied ARGB";
        case PixelFormat.Format8bppIndexed:
            return "8bpp Indexed";
        default:
            return format.ToString();
    }
}