I have to bind images from a SQLite database. The images are stores as BLOB (png file).
var image = new Image
{
HorizontalOptions = LayoutOptions.Start,
WidthRequest = 40,
HeightRequest = 40
};
var bnd = new Binding("Image", BindingMode.Default, new ArrayToImageConverter());
image.SetBinding(Image.SourceProperty, bnd);
How to define an "ArrayToImageConverter"
public abstract class ArrayToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
byte[] bmp = value as byte[];
if (bmp == null)
return null;
return new StreamImageSource
{
Stream = ?????
};
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new System.NotImplementedException();
}
}