using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.IO;
using System.Windows.Media.Imaging;

namespace BeWo.Scheduler.Converter
{
    public class BitmapToBitmapSourceConverter : IValueConverter
    {
        
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //return null;
            System.Drawing.Bitmap source = value as System.Drawing.Bitmap;
            if (source == null || targetType != typeof(ImageSource))
                return null;

            
            MemoryStream stream = new MemoryStream();
            source.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;

            BitmapImage result = new BitmapImage();
            result.BeginInit();
            result.StreamSource = stream;
            result.EndInit();
            //stream.Close();
            return result;
        }

            

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }



}