2023-03-03 19:25:33 +00:00
|
|
|
|
/* ImageSourceConverter.cs
|
|
|
|
|
* License: NCSA Open Source License
|
|
|
|
|
*
|
2024-05-21 20:15:19 +01:00
|
|
|
|
* Copyright: SPT
|
2023-03-03 19:25:33 +00:00
|
|
|
|
* AUTHORS:
|
|
|
|
|
* waffle.lord
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
using SPT.Launcher.Controllers;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
using Avalonia.Data.Converters;
|
|
|
|
|
using Avalonia.Media.Imaging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
namespace SPT.Launcher.Converters
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
|
|
|
|
public class ImageSourceConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
if (!(value is string valueString))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (value is string rawUri && targetType.IsAssignableFrom(typeof(Bitmap)))
|
|
|
|
|
{
|
|
|
|
|
return new Bitmap(rawUri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|