28 lines
930 B
C#
28 lines
930 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using Avalonia.Data;
|
|
using Avalonia.Data.Converters;
|
|
using Avalonia.Media.Imaging;
|
|
using Material.Icons;
|
|
using Material.Icons.Avalonia;
|
|
using TagLib;
|
|
|
|
namespace Ocarina2.Converter;
|
|
|
|
public class AlbumArtConverter:IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value == null) return new MaterialIconExt(MaterialIconKind.Music);
|
|
if(value is not IPicture[] p) return new BindingNotification(new InvalidCastException(), BindingErrorType.Error);
|
|
if(p.Length==0)return new MaterialIconExt(MaterialIconKind.Music);
|
|
var stream = new MemoryStream(p[0].Data.Data);
|
|
return new Bitmap(stream);
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |