ByteArrayToImageSourceConverter.cs 718 B

123456789101112131415161718192021222324
  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 bool BlankIfEmpty { get; set; }
  10. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  11. {
  12. if (value is byte[] bytes)
  13. return ImageSource.FromStream(() => new MemoryStream(bytes));
  14. return BlankIfEmpty ? null : ImageSource.FromFile("cross");
  15. }
  16. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  17. {
  18. throw new NotImplementedException();
  19. }
  20. }
  21. }