using System; using System.Drawing; using System.Windows; using System.Windows.Data; using System.Windows.Interop; using System.Windows.Media.Imaging; namespace FWindSoft.Wpf { public class BitmapToImageSourceConverter : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { BitmapSource bitmapSource = null; Bitmap bitmap = value as Bitmap; if (bitmap == null) return bitmapSource; try { bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } catch (Exception) { } return bitmapSource; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } }