mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 10:54:55 +08:00
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using Microsoft.UI.Xaml.Data;
|
|
using Microsoft.UI.Xaml.Media.Imaging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BetterLyrics.WinUI3.Converter
|
|
{
|
|
public partial class ByteArrayToImageConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
{
|
|
if (value is byte[] byteArray && byteArray.Length > 0)
|
|
{
|
|
try
|
|
{
|
|
using (var ms = new MemoryStream(byteArray))
|
|
{
|
|
var stream = ms.AsRandomAccessStream();
|
|
var bitmapImage = new BitmapImage();
|
|
|
|
bitmapImage.SetSource(stream);
|
|
|
|
return bitmapImage;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|