Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Fonte Link

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:

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:

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:

adicionou 21 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70

Seria basicamente:

Image image = new Image();
Stream stream = new MemoryStream(byteArray);    
image.Source = ImageSource.FromStream(stream() => {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:

Seria basicamente:

Image image = new Image();
Stream stream = new MemoryStream(byteArray);
image.Source = ImageSource.FromStream(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:

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:

adicionou 154 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70

Seria basicamente:

Image image = new Image();
Stream stream = new MemoryStream(byteArray);
image.Source = ImageSource.FromStream(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:

Seria basicamente:

Image image = new Image();
Stream stream = new MemoryStream(byteArray);
image.Source = ImageSource.FromStream(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:

Seria basicamente:

Image image = new Image();
Stream stream = new MemoryStream(byteArray);
image.Source = ImageSource.FromStream(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:

adicionou 279 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70
Carregando
adicionou 140 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70
Carregando
adicionou 140 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70
Carregando
adicionou 140 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70
Carregando
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70
Carregando