BitmapArrayValueConverter.cs 939 B

1234567891011121314151617181920212223242526272829303132333435
  1. using Avalonia.Data.Converters;
  2. using Avalonia.Media;
  3. using Avalonia.Media.Imaging;
  4. using System;
  5. using System.Globalization;
  6. using System.IO;
  7. namespace Ryujinx.Ava.UI.Helpers
  8. {
  9. internal class BitmapArrayValueConverter : IValueConverter
  10. {
  11. public static BitmapArrayValueConverter Instance = new();
  12. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  13. {
  14. if (value == null)
  15. {
  16. return null;
  17. }
  18. if (value is byte[] buffer && targetType == typeof(IImage))
  19. {
  20. MemoryStream mem = new(buffer);
  21. return new Bitmap(mem);
  22. }
  23. throw new NotSupportedException();
  24. }
  25. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  26. {
  27. throw new NotSupportedException();
  28. }
  29. }
  30. }