private static InteropBitmapFormat CheckFormat(InteropBitmapFormat format) { switch (format) { case InteropBitmapFormat.Rgb24: case InteropBitmapFormat.Rgba32: return(format); default: throw new ArgumentException($"Format '{format}' not supported", nameof(format)); } }
public InteropBitmap(int width, int height, float dpiX, float dpiY, InteropBitmapFormat format) { width.AssertGreaterThanZero(nameof(width)); height.AssertGreaterThanZero(nameof(height)); Width = width; Height = height; DpiX = dpiX; DpiY = dpiY; Format = CheckFormat(format); Bitmap = new WriteableBitmap(width, height, dpiX, dpiY, format.ToWpf(), null); }
public static System.Windows.Media.PixelFormat ToWpf(this InteropBitmapFormat format) { switch (format) { case InteropBitmapFormat.Rgb24: return(System.Windows.Media.PixelFormats.Bgr24); case InteropBitmapFormat.Rgba32: return(System.Windows.Media.PixelFormats.Bgra32); default: throw new ArgumentException($"Unknown value '{format}'", nameof(format)); } }
public static System.Drawing.Imaging.PixelFormat ToGdi(this InteropBitmapFormat format) { switch (format) { case InteropBitmapFormat.Rgb24: return(System.Drawing.Imaging.PixelFormat.Format24bppRgb); case InteropBitmapFormat.Rgba32: return(System.Drawing.Imaging.PixelFormat.Format32bppRgb); default: throw new ArgumentException($"Unknown value '{format}'", nameof(format)); } }