public static PixelFormat ToMediaPixelFormat( this System.Drawing.Imaging.PixelFormat pixelFormat) { try { return(PixelFormatDictionary.First(x => x.Value == pixelFormat).Key); } catch { throw new NotSupportedException("Type: " + pixelFormat + " is not supported by PixelFormatDictionary."); } }
/// <summary> /// Returns the compatible type of System.Drawing.Imaging.PixelFormat for a given System.Windows.Media.PixelFormat. /// </summary> /// <param name="pixelFormat"></param> /// <returns></returns> public static System.Drawing.Imaging.PixelFormat ToDrawingPixelFormat( this System.Windows.Media.PixelFormat pixelFormat) { if (!PixelFormatDictionary.ContainsKey(pixelFormat)) { throw new NotSupportedException("Type: " + pixelFormat + " is not supported by PixelFormatDictionary."); } return(PixelFormatDictionary[pixelFormat]); }