How to convert from System.Drawing.Imaging.PixelFormat to System.Windows.Media.PixelFormat

32 Views Asked by At

I'm converting a Bitmap to WritableBitmap, but they both have many formats, I can't figure out the corresponding relations.

I want to cover all convert conditions, so is there any official docs refer?

private System.Windows.Media.PixelFormat ConvertPixelFormats(PixelFormat pixelFormat)
{
    System.Windows.Media.PixelFormat format;
    switch (pixelFormat)
    {
        case PixelFormat.Format16bppRgb555:
            format = PixelFormats.Bgr555;
            break;
        case PixelFormat.Format16bppRgb565:
            format = PixelFormats.Bgr565;
            break;
        case PixelFormat.Format24bppRgb:
            format = PixelFormats.Bgr24;
            break;
        case PixelFormat.Format32bppRgb:
            format = PixelFormats.Bgr32;
            break;
        case PixelFormat.Format32bppPArgb:
            format = PixelFormats.Pbgra32;
            break;
        case PixelFormat.Format32bppArgb:
            format = PixelFormats.Bgra32;
            break;
        case PixelFormat.Format8bppIndexed:
            format = PixelFormats.Gray8;
            break;
    }

    return format;
}
0

There are 0 best solutions below