123456789101112131415161718192021222324252627282930313233343536 |
- 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();
- }
- }
- }
|