Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting System.Windows.Media.Color to System.Drawing.Color

Tags:

c#

colors

drawing

System.Windows.Media.Color mediacolor; // your color

var drawingcolor = System.Drawing.Color.FromArgb(
    mediacolor.A, mediacolor.R, mediacolor.G, mediacolor.B);

Just for reference... I use this:

using System.Runtime.CompilerServices;
using System.Windows.Media;

namespace HQ.Wpf.Util
{
    public static class ColorExtension
    {
        /// <summary>
        /// Convert Media Color (WPF) to Drawing Color (WinForm)
        /// </summary>
        /// <param name="mediaColor"></param>
        /// <returns></returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static System.Drawing.Color ToDrawingColor(this System.Windows.Media.Color mediaColor)
        {
            return System.Drawing.Color.FromArgb(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B);
        }

        /// <summary>
        /// Convert Drawing Color (WPF) to Media Color (WinForm)
        /// </summary>
        /// <param name="drawingColor"></param>
        /// <returns></returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static System.Windows.Media.Color ToMediaColor(this System.Drawing.Color drawingColor)
        {
            return System.Windows.Media.Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B);
        }