Seria basicamente:
Image image = new Image();
Stream stream = new MemoryStream(byteArray);
image.Source = ImageSource.FromStream(() => {return stream; });
onde byteArray
seria a variável corresponde byte[]
da sua imagem.
Segundo o site Xamarin - Binding an Image to a byte[] property on a model da resposta do usuário Casper Nybroe:
Code
public class ByteArrayToImageSourceConverter : IValueConverter
{
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
ImageSource retSource = null;
if (value != null)
{
byte[] imageAsBytes = (byte[])value;
retSource = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));
}
return retSource;
}
public object ConvertBack(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Xaml
<ContentPage.Resources>
<ResourceDictionary>
<converters:ByteArrayToImageSourceConverter x:Key="ByteArrayToImage" />
</ResourceDictionary>
</ContentPage.Resources>
<Image Source="{Binding SelectedPollItem.Image,
Converter={StaticResource ByteArrayToImage}}" />
Referencia:
- Load Image form byte[] array.
- Binding an Image to a byte[] property on a model
- IValueConverter Interface
- IValueConverter.Convert Method
- Convert Image into byte array in Xamarin.FormsConvert Image into byte array in Xamarin.Forms
- Xamarin.Forms.IValueConverter
- C# WPF XAML - Convert ImageSource from/to byte[] and display