Converting GDI+ PixelFormat to WPF PixelFormat

泄露秘密 提交于 2020-01-03 07:28:17

问题


What is the best way to get the System.Windows.Media.PixelFormats value equivalent to a System.Drawing.Imaging.PixelFormat ?


回答1:


This is a way of converting, so lets start here and see if someone can top this horrendeous contraption. They map well to eachother, so writing the switch cases should be fairly easy.

private static System.Windows.Media.PixelFormat ConvertPixelFormat(System.Drawing.Imaging.PixelFormat sourceFormat)
{
    switch (sourceFormat)
    {
        case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
            return PixelFormats.Bgr24;

        case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
            return PixelFormats.Bgra32;

        case System.Drawing.Imaging.PixelFormat.Format32bppRgb:
            return PixelFormats.Bgr32;

        // .. as many as you need...
    }
    return new System.Windows.Media.PixelFormat();
}



回答2:


The topic is very old but this is how I worked around this problem working under the assumption that both enumerations have all the same String values.

private static System.Windows.Media.PixelFormat ConvertPixelFormat (System.Drawing.Imaging.PixelFormat sourceFormat) { System.Windows.Media.PixelFormat pixelFormat = (System.Windows.Media.PixelFormat) Enum.Parse(typeof(System.Windows.Media.PixelFormat), sourceFormat.ToString());
return pixelFormat; }



来源:https://stackoverflow.com/questions/5106505/converting-gdi-pixelformat-to-wpf-pixelformat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!