首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将GDI+ PixelFormat转换为WPF PixelFormat

将GDI+ PixelFormat转换为WPF PixelFormat
EN

Stack Overflow用户
提问于 2011-02-24 23:12:10
回答 2查看 5.5K关注 0票数 10

获得等同于System.Drawing.Imaging.PixelFormatSystem.Windows.Media.PixelFormats值的最佳方法是什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-08-01 19:26:59

这是一种转换的方式,所以让我们从这里开始,看看是否有人能超越这个可怕的装置。它们相互映射得很好,所以编写切换用例应该相当容易。

代码语言:javascript
复制
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();
}
票数 8
EN

Stack Overflow用户

发布于 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());

代码语言:javascript
复制
 `return pixelFormat; }`
票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5106505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档