当前位置: 首页>>代码示例>>C#>>正文


C# OxyColor.ToBrush方法代码示例

本文整理汇总了C#中OxyColor.ToBrush方法的典型用法代码示例。如果您正苦于以下问题:C# OxyColor.ToBrush方法的具体用法?C# OxyColor.ToBrush怎么用?C# OxyColor.ToBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OxyColor的用法示例。


在下文中一共展示了OxyColor.ToBrush方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Export

        /// <summary>
        /// Exports the specified plot model to an xps file.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="fileName">The file name.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background color.</param>
        public static void Export(IPlotModel model, string fileName, double width, double height, OxyColor background)
        {
            using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                using (var doc = new XpsDocument(xpsPackage))
                {
                    var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
                    canvas.Measure(new Size(width, height));
                    canvas.Arrange(new Rect(0, 0, width, height));

                    var rc = new ShapesRenderContext(canvas);
#if !NET35
                    rc.TextFormattingMode = TextFormattingMode.Ideal;
#endif

                    model.Update(true);
                    model.Render(rc, width, height);

                    canvas.UpdateLayout();

                    var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
                    xpsdw.Write(canvas);
                }
            }
        }
开发者ID:benjaminrupp,项目名称:oxyplot,代码行数:33,代码来源:XpsExporter.cs

示例2: ExportToString

        /// <summary>
        /// Export the specified plot model to an xaml string.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background.</param>
        /// <returns>A xaml string.</returns>
        public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null)
        {
            var g = new Grid();
            if (background != null)
            {
                g.Background = background.ToBrush();
            }

            var c = new Canvas();
            g.Children.Add(c);

            var size = new Size(width, height);
            g.Measure(size);
            g.Arrange(new Rect(0, 0, width, height));
            g.UpdateLayout();

            var rc = new ShapesRenderContext(c) { UseStreamGeometry = false };
            model.Update();
            model.Render(rc, width, height);

            var sb = new StringBuilder();
            using (var sw = new StringWriter(sb))
            {
                var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true });
                XamlWriter.Save(c, xw);
            }

            return sb.ToString();
        }
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:37,代码来源:XamlExporter.cs

示例3: CreatePen

 private static Pen CreatePen(OxyColor stroke, double thickness, double[] dashArray,
                              LineJoin lineJoin = LineJoin.Miter)
 {
     if (stroke == null)
         return null;
     var pen = new Pen(stroke.ToBrush(), thickness);
     if (dashArray != null)
     {
         pen.DashStyle = new DashStyle(dashArray, 0);
     }
     switch (lineJoin)
     {
         case LineJoin.Round:
             pen.LineJoin = PenLineJoin.Round;
             break;
         case LineJoin.Bevel:
             pen.LineJoin = PenLineJoin.Bevel;
             break;
             //  The default LineJoin is Miter
     }
     return pen;
 }
开发者ID:Celderon,项目名称:oxyplot,代码行数:22,代码来源:DrawingRenderContext.cs

示例4: Export

        /// <summary>
        /// Exports the specified plot model to a xml writer.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="writer">The xml writer.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background.</param>
        private static void Export(IPlotModel model, XmlWriter writer, double width, double height, OxyColor background)
        {
            var c = new Canvas();
            if (background.IsVisible())
            {
                c.Background = background.ToBrush();
            }

            c.Measure(new Size(width, height));
            c.Arrange(new Rect(0, 0, width, height));

            var rc = new CanvasRenderContext(c) { UseStreamGeometry = false };

            rc.TextFormattingMode = TextFormattingMode.Ideal;

            model.Update(true);
            model.Render(rc, width, height);

            c.UpdateLayout();

            XamlWriter.Save(c, writer);
        }
开发者ID:apmKrauser,项目名称:RCUModulTest,代码行数:30,代码来源:XamlExporter.cs

示例5: GetCachedBrush

        /// <summary>
        /// Gets a brush from the cache or creates a new one.
        /// </summary>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <returns>
        /// The brush.
        /// </returns>
        private Brush GetCachedBrush(OxyColor stroke)
        {
            Brush brush;
            if (!this.brushCache.TryGetValue(stroke, out brush))
            {
                brush = stroke.ToBrush();
                this.brushCache.Add(stroke, brush);
            }

            return brush;
        }
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:20,代码来源:MetroRenderContext.cs

示例6: DrawText

        /// <summary>
        /// The draw text.
        /// </summary>
        /// <param name="p">
        /// The p.
        /// </param>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="fontFamily">
        /// The font family.
        /// </param>
        /// <param name="fontSize">
        /// The font size.
        /// </param>
        /// <param name="fontWeight">
        /// The font weight.
        /// </param>
        /// <param name="rotate">
        /// The rotate.
        /// </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 = fill.ToBrush() };

            // 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));

            double dx = 0;
            if (halign == OxyPlot.HorizontalAlignment.Center)
            {
                dx = -tb.ActualWidth / 2;
            }

            if (halign == OxyPlot.HorizontalAlignment.Right)
            {
                dx = -tb.ActualWidth;
            }

            double dy = 0;
            if (valign == OxyPlot.VerticalAlignment.Middle)
            {
                dy = -tb.ActualHeight / 2;
            }

            if (valign == OxyPlot.VerticalAlignment.Bottom)
            {
                dy = -tb.ActualHeight;
            }

            var transform = new TransformGroup();
            transform.Children.Add(new TranslateTransform { X = (int)dx, Y = (int)dy });
            if (!rotate.Equals(0.0))
            {
                transform.Children.Add(new RotateTransform { Angle = rotate });
            }

            transform.Children.Add(new TranslateTransform { X = (int)p.X, Y = (int)p.Y });
            tb.RenderTransform = transform;

            if (this.clip.HasValue)
            {
                // add a clipping container that is not rotated
                var c = new Canvas();
                c.Children.Add(tb);
                this.Add(c);
//.........这里部分代码省略.........
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:101,代码来源:MetroRenderContext.cs

示例7: DrawRectangle

        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="rect">
        /// The rectangle.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        public void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
        {
            var el = new Rectangle();
            if (stroke != null)
            {
                el.Stroke = stroke.ToBrush();
                el.StrokeThickness = thickness;
            }

            if (fill != null)
            {
                el.Fill = fill.ToBrush();
            }

            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);
        }
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:35,代码来源:MetroRenderContext.cs

示例8: ExportToBitmap

        /// <summary>
        /// Exports the specified plot model to a bitmap.
        /// </summary>
        /// <param name="model">The plot model.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background.</param>
        /// <param name="dpi">The resolution.</param>
        /// <returns>A bitmap.</returns>
        public static BitmapSource ExportToBitmap(PlotModel model, int width, int height, OxyColor background = null, int dpi = 96)
        {
            var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, width, height));

            var rc = new ShapesRenderContext(canvas) { RendersToScreen = false };
            model.Update();
            model.Render(rc, width, height);

            canvas.UpdateLayout();

            var bmp = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Pbgra32);
            bmp.Render(canvas);
            return bmp;

            // alternative implementation:
            // http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
            // var dv = new DrawingVisual();
            // using (var ctx = dv.RenderOpen())
            // {
            //    var vb = new VisualBrush(canvas);
            //    ctx.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
            // }
            // bmp.Render(dv);
        }
开发者ID:aleksanderkobylak,项目名称:oxyplot,代码行数:35,代码来源:PngExporter.cs

示例9: CreateFormattedText

        private FormattedText CreateFormattedText(string text, string fontFamily, double fontWeight, double fontSize,
                                                  OxyColor fill)
        {
            var fw = FontWeights.Normal;
            if (fontWeight >= 1 && fontWeight <= 999)
                fw = FontWeight.FromOpenTypeWeight((int) fontWeight);

            var typeface = new Typeface(
                new FontFamily(fontFamily),
                FontStyles.Normal,
                fw,
                FontStretches.Normal);

            return new FormattedText(text, CultureInfo.CurrentCulture,
                                     FlowDirection.LeftToRight,
                                     typeface, fontSize, fill.ToBrush());
        }
开发者ID:Celderon,项目名称:oxyplot,代码行数:17,代码来源:DrawingRenderContext.cs

示例10: DrawEllipse

        public void DrawEllipse(double x, double y, double width, double height, OxyColor fill, OxyColor stroke,
                                double thickness)
        {
            Brush brush = null;
            if (fill != null)
                brush = fill.ToBrush();

            var pen = CreatePen(stroke, thickness, null);
            var center = new Point(x + width/2, y + height/2);
            dc.DrawEllipse(brush, pen, center, width/2, height/2);
        }
开发者ID:Celderon,项目名称:oxyplot,代码行数:11,代码来源:DrawingRenderContext.cs

示例11: DrawRectangle

 public void DrawRectangle(double x, double y, double width, double height, OxyColor fill, OxyColor stroke,
                           double thickness)
 {
     Brush brush = null;
     if (fill != null)
         brush = fill.ToBrush();
     var pen = CreatePen(stroke, thickness, null);
     dc.DrawRectangle(brush, pen, new Rect(x, y, width, height));
 }
开发者ID:Celderon,项目名称:oxyplot,代码行数:9,代码来源:DrawingRenderContext.cs

示例12: DrawPolygon

        public void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness,
                                double[] dashArray, LineJoin lineJoin, bool aliased)
        {
            Brush brush = null;
            if (fill != null)
                brush = fill.ToBrush();

            var pen = CreatePen(stroke, thickness, dashArray, lineJoin);
            var g = CreateGeometry(points, true);

            dc.DrawGeometry(brush, pen, g);
        }
开发者ID:Celderon,项目名称:oxyplot,代码行数:12,代码来源:DrawingRenderContext.cs


注:本文中的OxyColor.ToBrush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。