ByteArrayToImageSourceConverter.cs 498 B

1234567891011121314151617
  1. using System.Globalization;
  2. using Avalonia.Data.Converters;
  3. using Avalonia.Media.Imaging;
  4. namespace InABox.Avalonia.Converters;
  5. public class ByteArrayToImageSourceConverter : AbstractConverter<byte[], Bitmap?>
  6. {
  7. protected override Bitmap? Convert(byte[]? value, object? parameter = null)
  8. {
  9. Bitmap? result = null;
  10. if (value is byte[] bytes)
  11. using (var stream = new MemoryStream(bytes))
  12. result = new Bitmap(stream);
  13. return result;
  14. }
  15. }