本文整理汇总了C#中OxyColor.ToColor方法的典型用法代码示例。如果您正苦于以下问题:C# OxyColor.ToColor方法的具体用法?C# OxyColor.ToColor怎么用?C# OxyColor.ToColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OxyColor
的用法示例。
在下文中一共展示了OxyColor.ToColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawEllipse
public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness = 1)
{
using (var paint = new Paint())
{
paint.AntiAlias = true;
paint.StrokeWidth = (float)thickness;
if (fill != null)
{
paint.SetStyle(Paint.Style.Fill);
paint.Color = stroke.ToColor();
canvas.DrawOval(rect.ToRectF(), paint);
}
if (stroke != null)
{
paint.SetStyle(Paint.Style.Stroke);
paint.Color = stroke.ToColor();
canvas.DrawOval(rect.ToRectF(), paint);
}
}
}
示例2: DrawText
public void DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize,
double fontWeight, double rotate, HorizontalAlignment halign, VerticalTextAlign valign)
{
var tb = new TextBlock
{
Text = text,
Foreground = new SolidColorBrush(fill.ToColor())
};
if (fontFamily != null)
tb.FontFamily = new FontFamily(fontFamily);
if (fontSize > 0)
tb.FontSize = fontSize;
if (fontWeight > 0)
tb.FontWeight = FontWeight.FromOpenTypeWeight((int)fontWeight);
tb.Measure(new Size(1000, 1000));
double dx = 0;
if (halign == HorizontalAlignment.Center)
dx = -tb.DesiredSize.Width / 2;
if (halign == HorizontalAlignment.Right)
dx = -tb.DesiredSize.Width;
double dy = 0;
if (valign == VerticalTextAlign.Middle)
dy = -tb.DesiredSize.Height / 2;
if (valign == VerticalTextAlign.Bottom)
dy = -tb.DesiredSize.Height;
var transform = new TransformGroup();
transform.Children.Add(new TranslateTransform(dx, dy));
if (rotate != 0)
transform.Children.Add(new RotateTransform(rotate));
transform.Children.Add(new TranslateTransform(p.X, p.Y));
tb.RenderTransform = transform;
tb.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Enabled);
Add(tb);
}
示例3: DrawEllipse
public void DrawEllipse(double x, double y, double width, double height, OxyColor fill, OxyColor stroke,
double thickness)
{
var el = new Ellipse();
if (stroke != null)
{
el.Stroke = new SolidColorBrush(stroke.ToColor());
el.StrokeThickness = thickness;
}
if (fill != null)
{
el.Fill = new SolidColorBrush(fill.ToColor());
}
el.Width = width;
el.Height = height;
Canvas.SetLeft(el, x);
Canvas.SetTop(el, y);
Add(el);
}
示例4: GetCachedBrush
private Brush GetCachedBrush(OxyColor stroke)
{
Brush brush;
if (!brushCache.TryGetValue(stroke, out brush))
{
brush = new SolidColorBrush(stroke.ToColor());
brush.Freeze();
brushCache.Add(stroke, brush);
}
return brush;
}
示例5: DrawText
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="p">The position.</param>
/// <param name="text">The text.</param>
/// <param name="fill">The fill color.</param>
/// <param name="fontFamily">The font family.</param>
/// <param name="fontSize">Size of the font.</param>
/// <param name="fontWeight">The font weight.</param>
/// <param name="rotate">The rotation angle.</param>
/// <param name="halign">The horizontal alignment.</param>
/// <param name="valign">The vertical alignment.</param>
/// <param name="maxSize">The maximum size of the text.</param>
public void DrawText(
ScreenPoint p,
string text,
OxyColor fill,
string fontFamily,
double fontSize,
double fontWeight,
double rotate,
OxyPlot.HorizontalAlignment halign,
OxyPlot.VerticalAlignment valign,
OxySize? maxSize)
{
var tb = new TextBlock { Text = text, Foreground = new SolidColorBrush(fill.ToColor()) };
// tb.SetValue(TextOptions.TextHintingModeProperty, TextHintingMode.Animated);
if (fontFamily != null)
{
tb.FontFamily = new FontFamily(fontFamily);
}
if (fontSize > 0)
{
tb.FontSize = fontSize;
}
tb.FontWeight = GetFontWeight(fontWeight);
tb.Measure(new Size(1000, 1000));
var size = new Size(tb.ActualWidth, tb.ActualHeight);
if (maxSize != null)
{
if (size.Width > maxSize.Value.Width)
{
size.Width = maxSize.Value.Width;
}
if (size.Height > maxSize.Value.Height)
{
size.Height = maxSize.Value.Height;
}
tb.Clip = new RectangleGeometry { Rect = new Rect(0, 0, size.Width, size.Height) };
}
double dx = 0;
if (halign == OxyPlot.HorizontalAlignment.Center)
{
dx = -size.Width / 2;
}
if (halign == OxyPlot.HorizontalAlignment.Right)
{
dx = -size.Width;
}
double dy = 0;
if (valign == OxyPlot.VerticalAlignment.Middle)
{
dy = -size.Height / 2;
}
if (valign == OxyPlot.VerticalAlignment.Bottom)
{
dy = -size.Height;
}
var transform = new TransformGroup();
transform.Children.Add(new TranslateTransform { X = (int)dx, Y = (int)dy });
if (!rotate.Equals(0))
{
transform.Children.Add(new RotateTransform { Angle = rotate });
}
transform.Children.Add(new TranslateTransform { X = (int)p.X, Y = (int)p.Y });
tb.RenderTransform = transform;
this.ApplyTooltip(tb);
if (this.clip)
{
// add a clipping container that is not rotated
var c = new Canvas();
c.Children.Add(tb);
this.Add(c);
}
else
{
this.Add(tb);
//.........这里部分代码省略.........
示例6: DrawRectangle
/// <summary>
/// Draws the rectangle.
/// </summary>
/// <param name="rect">The rectangle.</param>
/// <param name="fill">The fill color.</param>
/// <param name="stroke">The stroke color.</param>
/// <param name="thickness">The stroke thickness.</param>
public void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
{
var el = new Rectangle();
if (stroke.IsVisible())
{
el.Stroke = new SolidColorBrush(stroke.ToColor());
el.StrokeThickness = thickness;
}
if (fill.IsVisible())
{
el.Fill = new SolidColorBrush(fill.ToColor());
}
el.Width = rect.Width;
el.Height = rect.Height;
Canvas.SetLeft(el, rect.Left);
Canvas.SetTop(el, rect.Top);
this.Add(el, rect.Left, rect.Top);
}
示例7: SetStroke
/// <summary>
/// Sets the stroke style.
/// </summary>
/// <param name="stroke">The stroke color.</param>
/// <param name="thickness">The stroke thickness.</param>
/// <param name="dashArray">The dash array.</param>
/// <param name="lineJoin">The line join.</param>
/// <param name="aliased">Use aliased strokes if set to <c>true</c>.</param>
private void SetStroke(OxyColor stroke, double thickness, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
{
this.paint.SetStyle(Paint.Style.Stroke);
this.paint.Color = stroke.ToColor();
this.paint.StrokeWidth = this.Convert(thickness);
this.paint.StrokeJoin = lineJoin.Convert();
if (dashArray != null)
{
var dashArrayF = dashArray.Select(this.Convert).ToArray();
this.paint.SetPathEffect(new DashPathEffect(dashArrayF, 0f));
}
this.paint.AntiAlias = !aliased;
}
示例8: SetFill
/// <summary>
/// Sets the fill style.
/// </summary>
/// <param name="fill">The fill color.</param>
private void SetFill(OxyColor fill)
{
this.paint.SetStyle(Paint.Style.Fill);
this.paint.Color = fill.ToColor();
this.paint.AntiAlias = true;
}
示例9: DrawText
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="p">The position of the text.</param>
/// <param name="text">The text.</param>
/// <param name="fill">The fill color.</param>
/// <param name="fontFamily">The font family.</param>
/// <param name="fontSize">Size of the font.</param>
/// <param name="fontWeight">The font weight.</param>
/// <param name="rotate">The rotation angle.</param>
/// <param name="halign">The horizontal alignment.</param>
/// <param name="valign">The vertical alignment.</param>
/// <param name="maxSize">The maximum size of the text.</param>
public override void DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalAlignment halign, VerticalAlignment valign, OxySize? maxSize)
{
this.paint.Reset();
{
this.paint.AntiAlias = true;
this.paint.TextSize = this.Convert(fontSize);
this.paint.Color = fill.ToColor();
float width;
float height;
if (maxSize.HasValue || halign != HorizontalAlignment.Left || valign != VerticalAlignment.Bottom)
{
this.paint.GetTextBounds(text, 0, text.Length, this.bounds);
width = this.bounds.Width();
height = this.bounds.Height();
}
else
{
width = height = 0f;
}
if (maxSize.HasValue)
{
var maxWidth = this.Convert(maxSize.Value.Width);
var maxHeight = this.Convert(maxSize.Value.Height);
if (width > maxWidth)
{
width = maxWidth;
}
if (height > maxSize.Value.Height)
{
height = maxHeight;
}
}
var dx = halign == HorizontalAlignment.Left ? 0d : (halign == HorizontalAlignment.Center ? -width * 0.5 : -width);
var dy = valign == VerticalAlignment.Bottom ? 0d : (valign == VerticalAlignment.Middle ? height * 0.5 : height);
this.canvas.Save();
this.canvas.Translate(this.Convert(p.X), this.Convert(p.Y));
this.canvas.Rotate((float)rotate);
this.canvas.Translate((float)dx, (float)dy);
if (maxSize.HasValue)
{
this.canvas.ClipRect(0, -height, this.Convert(maxSize.Value.Width), 0);
}
this.canvas.DrawText(text, 0, 0, this.paint);
this.canvas.Restore();
}
}
示例10: DrawEllipses
public void DrawEllipses(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness = 1)
{
using (var paint = new Paint())
{
paint.AntiAlias = true;
paint.StrokeWidth = (float)thickness;
foreach (var rect in rectangles)
{
if (fill != null)
{
paint.SetStyle(Paint.Style.Fill);
paint.Color = fill.ToColor();
canvas.DrawOval(rect.ToRectF(), paint);
}
if (stroke != null)
{
paint.SetStyle(Paint.Style.Stroke);
paint.Color = stroke.ToColor();
canvas.DrawOval(rect.ToRectF(), paint);
}
}
}
}
示例11: DrawText
public void DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily = null, double fontSize = 10, double fontWeight = 500, double rotate = 0, OxyPlot.HorizontalAlignment halign = HorizontalAlignment.Left, VerticalAlignment valign = VerticalAlignment.Top, OxySize? maxSize = new OxySize?())
{
using (var paint = new Paint())
{
paint.AntiAlias = true;
paint.TextSize = (float)fontSize;
paint.Color = fill.ToColor();
var bounds = new Rect();
paint.GetTextBounds(text, 0, text.Length, bounds);
float dx = 0;
if (halign == HorizontalAlignment.Center)
{
dx = -bounds.Width() / 2;
}
if (halign == HorizontalAlignment.Right)
{
dx = -bounds.Width();
}
float dy = 0;
if (valign == VerticalAlignment.Middle)
{
dy = +bounds.Height() / 2;
}
if (valign == VerticalAlignment.Top)
{
dy = bounds.Height();
}
canvas.Save();
canvas.Translate(dx, dy);
canvas.Rotate((float)rotate);
canvas.Translate((float)p.X, (float)p.Y);
canvas.DrawText(text, 0, 0, paint);
canvas.Restore();
}
}
示例12: DrawRectangle
public void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness = 1)
{
using (var paint = new Paint())
{
paint.AntiAlias = false;
paint.StrokeWidth = (float)thickness;
if (fill != null)
{
paint.SetStyle(Paint.Style.Fill);
paint.Color = fill.ToColor();
canvas.DrawRect((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom, paint);
}
if (stroke != null)
{
paint.SetStyle(Paint.Style.Stroke);
paint.Color = stroke.ToColor();
canvas.DrawRect((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom, paint);
}
}
}
示例13: DrawPolygon
public void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness = 1, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
{
using (var paint = new Paint())
{
paint.AntiAlias = !aliased;
paint.StrokeWidth = (float)thickness;
using (var path = new Path())
{
path.MoveTo((float)points[0].X, (float)points[0].Y);
for (int i = 1; i <= points.Count; i++)
{
path.LineTo((float)points[i % points.Count].X, (float)points[i % points.Count].Y);
}
if (fill != null)
{
paint.SetStyle(Paint.Style.Fill);
paint.Color = fill.ToColor();
canvas.DrawPath(path, paint);
}
if (stroke != null)
{
paint.SetStyle(Paint.Style.Stroke);
paint.Color = stroke.ToColor();
canvas.DrawPath(path, paint);
}
}
}
}
示例14: DrawLineSegments
public void DrawLineSegments(IList<ScreenPoint> points, OxyColor stroke, double thickness = 1, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
{
using (var paint = new Paint())
{
paint.StrokeWidth = (float)thickness;
paint.Color = stroke.ToColor();
paint.AntiAlias = !aliased;
var pts = new float[points.Count * 2];
int i = 0;
foreach (var p in points)
{
pts[i++] = (float)p.X;
pts[i++] = (float)p.Y;
}
canvas.DrawLines(pts, paint);
}
}
示例15: DrawLine
public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness = 1, double[] dashArray = null, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, bool aliased = false)
{
using (var paint = new Paint())
{
paint.StrokeWidth = (float)thickness;
paint.Color = stroke.ToColor();
paint.AntiAlias = !aliased;
var pts = new float[(points.Count - 1) * 4];
int j = 0;
for (int i = 0; i + 1 < points.Count; i++)
{
pts[j++] = (float)points[i].X;
pts[j++] = (float)points[i].Y;
pts[j++] = (float)points[i + 1].X;
pts[j++] = (float)points[i + 1].Y;
}
canvas.DrawLines(pts, paint);
}
}