获得等同于System.Drawing.Imaging.PixelFormat的System.Windows.Media.PixelFormats值的最佳方法是什么?
发布于 2011-08-01 19:26:59
这是一种转换的方式,所以让我们从这里开始,看看是否有人能超越这个可怕的装置。它们相互映射得很好,所以编写切换用例应该相当容易。
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();
}发布于 2015-04-16 02:45:39
这个话题很古老,但这就是我在假设两个枚举都有相同的字符串值的情况下解决这个问题的方法。
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
复制相似问题