First, we will create a converter that will convert a byte[] to Xamarin.Forms.ImageSource. In the GalleryApp project, create a new folder named Converters, and inside the folder, create a new class named BytesToImageConverter:
public class BytesToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
var bytes = (byte[])value;
var stream = new MemoryStream(bytes);
return ImageSource.FromStream(() => stream);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
To use the converter, we need to add it as a resource. We will do this by adding it to a ResourceDictionary object in the Resources property of GalleryView:
- Open GalleryView.xaml.
- Add...