BitmapArrayValueConverter.cs
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 8 namespace Ryujinx.Ava.UI.Helpers 9 { 10 internal class BitmapArrayValueConverter : IValueConverter 11 { 12 public static BitmapArrayValueConverter Instance = new(); 13 14 public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 { 16 if (value == null) 17 { 18 return null; 19 } 20 21 if (value is byte[] buffer && targetType == typeof(IImage)) 22 { 23 MemoryStream mem = new(buffer); 24 25 return new Bitmap(mem); 26 } 27 28 throw new NotSupportedException(); 29 } 30 31 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 32 { 33 throw new NotSupportedException(); 34 } 35 } 36 }