naps2/NAPS2.Images.Wpf/WpfExtensions.cs
2023-12-30 12:41:48 -08:00

19 lines
667 B
C#

using System.Windows.Media.Imaging;
namespace NAPS2.Images.Wpf;
public static class WpfExtensions
{
public static BitmapSource RenderToBitmapSource(this IRenderableImage image)
{
var wpfImageContext = image.ImageContext as WpfImageContext ??
throw new ArgumentException("The provided image does not have a WpfImageContext");
return wpfImageContext.RenderToBitmapSource(image);
}
public static BitmapSource AsBitmapSource(this IMemoryImage image)
{
var wpfImage = image as WpfImage ?? throw new ArgumentException("Expected a WpfImage", nameof(image));
return wpfImage.Bitmap;
}
}