Exemple #1
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ColorUtils.MediaColorToDrawingColor((System.Windows.Media.Color)value));
 }
Exemple #2
0
 public static System.Drawing.Color ToDrawingColor(this System.Windows.Media.Color self)
 {
     return(ColorUtils.MediaColorToDrawingColor(self));
 }
Exemple #3
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => ColorUtils.MediaColorToDrawingColor((MediaColor)value);
Exemple #4
0
        public static System.Drawing.Brush MediaBrushToDrawingBrush(System.Windows.Media.Brush in_brush)
        {
            if (in_brush is System.Windows.Media.SolidColorBrush)
            {
                System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(
                    ColorUtils.MediaColorToDrawingColor((in_brush as System.Windows.Media.SolidColorBrush).Color)
                    );

                return(brush);
            }
            else if (in_brush is System.Windows.Media.LinearGradientBrush)
            {
                System.Windows.Media.LinearGradientBrush lgb = (in_brush as System.Windows.Media.LinearGradientBrush);

                System.Drawing.PointF starting_point = new System.Drawing.PointF(
                    (float)lgb.StartPoint.X,
                    (float)lgb.StartPoint.Y
                    );

                System.Drawing.PointF ending_point = new System.Drawing.PointF(
                    (float)lgb.EndPoint.X,
                    (float)lgb.EndPoint.Y
                    );

                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
                    starting_point,
                    ending_point,
                    System.Drawing.Color.Red,
                    System.Drawing.Color.Red
                    );

                /*
                 * switch(lgb.SpreadMethod)
                 * {
                 *  case System.Windows.Media.GradientSpreadMethod.Pad:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Reflect:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Repeat:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                 *      break;
                 * }
                 */

                SortedDictionary <float, System.Drawing.Color> brush_blend = new SortedDictionary <float, System.Drawing.Color>();

                foreach (var grad_stop in lgb.GradientStops)
                {
                    if (!brush_blend.ContainsKey((float)grad_stop.Offset))
                    {
                        brush_blend.Add((float)grad_stop.Offset, ColorUtils.MediaColorToDrawingColor(grad_stop.Color));
                    }
                }

                List <System.Drawing.Color> brush_colors = new List <System.Drawing.Color>();
                List <float> brush_positions             = new List <float>();

                foreach (var kvp in brush_blend)
                {
                    brush_colors.Add(kvp.Value);
                    brush_positions.Add(kvp.Key);
                }

                System.Drawing.Drawing2D.ColorBlend color_blend = new System.Drawing.Drawing2D.ColorBlend();
                color_blend.Colors        = brush_colors.ToArray();
                color_blend.Positions     = brush_positions.ToArray();
                brush.InterpolationColors = color_blend;

                return(brush);
            }
            else if (in_brush is System.Windows.Media.RadialGradientBrush)
            {
                System.Windows.Media.RadialGradientBrush rgb = (in_brush as System.Windows.Media.RadialGradientBrush);

                System.Drawing.RectangleF brush_region = new System.Drawing.RectangleF(
                    0.0f,
                    0.0f,
                    2.0f * (float)rgb.RadiusX,
                    2.0f * (float)rgb.RadiusY
                    );

                System.Drawing.PointF center_point = new System.Drawing.PointF(
                    (float)rgb.Center.X,
                    (float)rgb.Center.Y
                    );

                System.Drawing.Drawing2D.GraphicsPath g_path = new System.Drawing.Drawing2D.GraphicsPath();
                g_path.AddEllipse(brush_region);

                System.Drawing.Drawing2D.PathGradientBrush brush = new System.Drawing.Drawing2D.PathGradientBrush(g_path);

                brush.CenterPoint = center_point;

                /*
                 * switch (rgb.SpreadMethod)
                 * {
                 *  case System.Windows.Media.GradientSpreadMethod.Pad:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Reflect:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Repeat:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                 *      break;
                 * }
                 */

                SortedDictionary <float, System.Drawing.Color> brush_blend = new SortedDictionary <float, System.Drawing.Color>();

                foreach (var grad_stop in rgb.GradientStops)
                {
                    if (!brush_blend.ContainsKey((float)grad_stop.Offset))
                    {
                        brush_blend.Add((float)grad_stop.Offset, ColorUtils.MediaColorToDrawingColor(grad_stop.Color));
                    }
                }

                List <System.Drawing.Color> brush_colors = new List <System.Drawing.Color>();
                List <float> brush_positions             = new List <float>();

                foreach (var kvp in brush_blend)
                {
                    brush_colors.Add(kvp.Value);
                    brush_positions.Add(kvp.Key);
                }

                System.Drawing.Drawing2D.ColorBlend color_blend = new System.Drawing.Drawing2D.ColorBlend();
                color_blend.Colors        = brush_colors.ToArray();
                color_blend.Positions     = brush_positions.ToArray();
                brush.InterpolationColors = color_blend;

                return(brush);
            }
            else
            {
                return(new System.Drawing.SolidBrush(System.Drawing.Color.Red)); //Return error color
            }
        }
Exemple #5
0
 public static DrawingColor ToDrawingColor(this MediaColor self)
 {
     return(ColorUtils.MediaColorToDrawingColor(self));
 }