将GDI+ PixelFormat转换为WPF PixelFormat。

时间:2022-02-22 14:17:41

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

什么是获得系统、窗口、媒体的最佳方式?像素格式的值相当于一个系统。绘制。成像。PixelFormat吗?

2 个解决方案

#1


8  

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


-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; }

私有静态System.Windows.Media。PixelFormat ConvertPixelFormat(System.Drawing.Imaging。{ System.Windows.Media PixelFormat sourceFormat)。PixelFormat = (System.Windows.Media.PixelFormat) Enum.Parse(typeof(System.Windows.Media.PixelFormat), sourceFormat.ToString();返回pixelFormat;}

#1


8  

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


-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; }

私有静态System.Windows.Media。PixelFormat ConvertPixelFormat(System.Drawing.Imaging。{ System.Windows.Media PixelFormat sourceFormat)。PixelFormat = (System.Windows.Media.PixelFormat) Enum.Parse(typeof(System.Windows.Media.PixelFormat), sourceFormat.ToString();返回pixelFormat;}