Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting GDI+ PixelFormat to WPF PixelFormat

Tags:

wpf

gdi+

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

like image 233
Jem Avatar asked Feb 24 '11 15:02

Jem


1 Answers

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();
}
like image 159
Anders Forsgren Avatar answered Oct 02 '22 03:10

Anders Forsgren