ByteArrayToImageSourceConverter.cs 648 B

12345678910111213141516171819202122
  1. using System;
  2. using System.Globalization;
  3. using System.IO;
  4. using Xamarin.Forms;
  5. namespace InABox.Mobile
  6. {
  7. public class ByteArrayToImageSourceConverter : IValueConverter
  8. {
  9. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  10. {
  11. if (value is byte[] bytes)
  12. return ImageSource.FromStream(() => new MemoryStream(bytes));
  13. return ImageSource.FromFile("cross");
  14. }
  15. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. throw new NotImplementedException();
  18. }
  19. }
  20. }