mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Sidebar - Truncate long profile names Profile editor - Added shift+click on eye-icon in profile tree to focus an element Profile editor - Fixed layer property prefix/affix vertical alignment UI - Made shutdown via tray more responsive UI - Fixed several memory leaks
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace Artemis.UI.Shared
|
|
{
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Converts bitmap file in the form of a <see cref="T:Stream" /> into <see cref="T:BitmapImage" />.
|
|
/// </summary>
|
|
[ValueConversion(typeof(Stream), typeof(BitmapImage))]
|
|
public class StreamToBitmapImageConverter : IValueConverter
|
|
{
|
|
/// <inheritdoc />
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is not Stream stream)
|
|
return null;
|
|
|
|
stream.Position = 0;
|
|
|
|
BitmapImage selectedBitmap = new();
|
|
selectedBitmap.BeginInit();
|
|
selectedBitmap.StreamSource = stream;
|
|
selectedBitmap.CacheOption = BitmapCacheOption.OnLoad;
|
|
selectedBitmap.EndInit();
|
|
selectedBitmap.Freeze();
|
|
|
|
stream.Position = 0;
|
|
return selectedBitmap;
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return Binding.DoNothing;
|
|
}
|
|
}
|
|
} |