//
// Copyright (c) 2015, MindFusion LLC - Bulgaria.
//

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


namespace MindFusion.Reporting.Wpf.Samples.CS.Portfolio
{
	public class ImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value is byte[])
			{
				MemoryStream stream = new MemoryStream(value as byte[]);

				BitmapImage image = new BitmapImage();
				image.BeginInit();
				image.StreamSource = stream;
				image.EndInit();
				return image;
			}

			return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
