Skip to content

Instantly share code, notes, and snippets.

@programmation
Created July 27, 2015 02:53
Show Gist options
  • Save programmation/4e4131924c02aee4fc1d to your computer and use it in GitHub Desktop.
Save programmation/4e4131924c02aee4fc1d to your computer and use it in GitHub Desktop.
Convert byte array to ImageSource
// http://forums.xamarin.com/discussion/comment/89964/#Comment_89964
namespace Core.Converters
{
public class ByteArrayToImageSource : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || value is DBNull)
return null;
var bArray = (byte[]) value;
var imgsrc = ImageSource.FromStream(() => {
var ms = new MemoryStream(bArray);
ms.Position = 0;
return ms;
});
return imgsrc;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment