ini
This commit is contained in:
44
ProjetTheAlone/Converter/BinaryImageConverter.cs
Normal file
44
ProjetTheAlone/Converter/BinaryImageConverter.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media.Imaging;
|
||||
//https://cromwellhaus.com/2007/07/binding-to-the-byte-of-an-image-in-wpf/
|
||||
namespace ProjetTheAlone.Converter
|
||||
{
|
||||
public class BinaryImageConverter : IValueConverter
|
||||
{
|
||||
object IValueConverter.Convert(object value,
|
||||
Type targetType,
|
||||
object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value != null && value is byte[])
|
||||
{
|
||||
byte[] bytes = value as byte[];
|
||||
|
||||
MemoryStream stream = new MemoryStream(bytes);
|
||||
|
||||
BitmapImage image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.StreamSource = stream;
|
||||
image.EndInit();
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
object IValueConverter.ConvertBack(object value,
|
||||
Type targetType,
|
||||
object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new Exception("The method or operation is not implemented.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user