using System;
using System.Windows.Media;
using SDColor = System.Drawing.Color;//Add it from Assemblies
using SWMColor = System.Windows.Media.Color;
using SWMBrush = System.Windows.Media.Brush;
using System.Reflection;
public static class ConverterColors
{
public static SWMColor ToSWMColor(SDColor color) => SWMColor.FromArgb(color.A, color.R, color.G, color.B);
public static SDColor ToSDColor(SWMColor color) => SDColor.FromArgb(color.A, color.R, color.G, color.B);
public static SWMBrush ToSWMBrush(SDColor color) => (SolidColorBrush)(new BrushConverter().ConvertFrom(ToHexColor(color)));
public static string ToHexColor(SDColor c) => "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
public static string ToRGBColor(SDColor c) => "RGB(" + c.R.ToString() + "," + c.G.ToString() + "," + c.B.ToString() + ")";
public static Tuple<SDColor, SDColor> GetColorFromRYGGradient(double percentage)
{
var red = (percentage > 50 ? 1 - 2 * (percentage - 50) / 100.0 : 1.0) * 255;
var green = (percentage > 50 ? 1.0 : 2 * percentage / 100.0) * 255;
var blue = 0.0;
SDColor result1 = SDColor.FromArgb((int)red, (int)green, (int)blue);
SDColor result2 = SDColor.FromArgb((int)green, (int)red, (int)blue);
return new Tuple<SDColor, SDColor>(result1, result2);
}
}
//=======================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Brush_to_Color
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
System.Drawing.Color color1 = ConverterColors.ToSDColor(System.Windows.Media.Colors.Red);
System.Drawing.Color color4 = ConverterColors.ToSDColor(System.Windows.Media.Brushes.Red.Color);
System.Windows.Media.Color color2 = ConverterColors.ToSWMColor(System.Drawing.Color.Red);
System.Windows.Media.Brush color3 = ConverterColors.ToSWMBrush(System.Drawing.Color.Red);
}
}
}
Download the project of Visual Studio 2022 in DropBox Download