Files
Shrlalgo.RvKits/Melskin/Converters/Internal/IntensityToEmbossBlurConverter.cs
2026-02-17 22:17:13 +08:00

31 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Globalization;
using System.Windows.Data;
namespace Melskin.Converters.Internal;
/// <summary>
/// IntensityToSlotBlurConverter 类实现 IValueConverter 接口,用于将给定的强度值转换为模糊效果的数值。
/// 此转换器接收一个 double 类型的强度值,并将其转换为对应的模糊效果大小。模糊效果的范围是从 4 到 12
/// 其中强度值越大,产生的模糊效果越强。
/// </summary>
[ValueConversion(typeof(double), typeof(double))]
internal sealed class IntensityToEmbossBlurConverter : IValueConverter
{
/// <summary>
/// Instance 是 IntensityToSlotBlurConverter 类的单例实例,用于在整个应用程序中共享同一转换器对象。
/// 通过使用此单例,可以避免在不同地方创建多个相同功能的转换器实例,从而提高性能和减少资源消耗。
/// </summary>
public static readonly IntensityToEmbossBlurConverter Instance = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var intensity = (double)(value ?? 1);
//数值最大的时候,模糊达到预设最大值 4~12
//return 4 + intensity * 8;
return 4 + intensity * 8;
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}