ScpDriverInstaller/Utilities/BitmapToImageSourceConverter.cs (31 lines of code) (raw):
using System;
using System.Drawing;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ScpDriverInstaller.Utilities
{
[ValueConversion(typeof(Bitmap), typeof(ImageSource))]
public class BitmapToImageSource : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var bmp = value as System.Drawing.Bitmap;
if (bmp == null) { return null; }
else
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bmp.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// Because we're not going to use it, but it is required by IValueConverter
throw new NotImplementedException();
}
}
}