45 lines
1.7 KiB
C#
45 lines
1.7 KiB
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
|
|
{
|
|
/*
|
|
OCARINA2 Open-source music player and library manager
|
|
Copyright (C) 2023 Matyáš Caras
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
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();
|
|
}
|
|
} |