wpf - 将 GDI+ PixelFormat 转换为 WPF PixelFormat

标签 wpf gdi+

获得System.Windows.Media.PixelFormats 的最佳方式是什么?相当于 System.Drawing.Imaging.PixelFormat 的值?

最佳答案

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

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

关于wpf - 将 GDI+ PixelFormat 转换为 WPF PixelFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5106505/

相关文章:

.net - WPF ColumnDefinition 自动宽度 MinWidth 绑定(bind)

c# - 在 XAML 中设置 DataContext

c# - 将原始 RGB 字节数组转换为 JPG 编码的字符串 base64

c++ - 如何使用 GDIPLUS 绘制第二台显示器

c++ - gdipluspath 为 cstddef 和 rpcndr.h 抛出不明确的字节

c# - 从其他程序集实例化 ResourceDictionary xaml

c# - 为什么 Canvas 的子元素不会移动?

c# - TextBlock.GetBindingExpression 返回 NULL

c++ - WinAPI:无法完全摆脱窗口框架

c# - 使用c#在两条线之间绘制链接或路径