private void DrawLine(DXMediaBrush brush, double x1, double y1, double x2, double y2, float width, DashStyleHelper dashStyle) { SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties(); if (dashStyle == DashStyleHelper.Dash) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash; } if (dashStyle == DashStyleHelper.DashDot) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot; } if (dashStyle == DashStyleHelper.DashDotDot) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot; } if (dashStyle == DashStyleHelper.Dot) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot; } if (dashStyle == DashStyleHelper.Solid) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid; } SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFactory, ssProps); SharpDX.Vector2 startPoint = new System.Windows.Point(x1, y1).ToVector2(); SharpDX.Vector2 endPoint = new System.Windows.Point(x2, y2).ToVector2(); RenderTarget.DrawLine(startPoint, endPoint, brush.DxBrush, width, strokeStyle); strokeStyle.Dispose(); strokeStyle = null; }
private void _drawSelectedTile(SharpDX.Direct2D1.DeviceContext d2dContext) { if (_selectedRect != null) { var strokeStyle_dashed = new SharpDX.Direct2D1.StrokeStyle(d2dContext.Factory, new SharpDX.Direct2D1.StrokeStyleProperties() { DashOffset = (offsetSelectedDash / 5), DashStyle = SharpDX.Direct2D1.DashStyle.Dash }); ////drown out the shadow of the tile //d2dContext.DrawRectangle( // new RectangleF(_selectedRect.Rectangle.X - 2, _selectedRect.Rectangle.Y - 2, _selectedRect.Rectangle.Width + 4, _selectedRect.Rectangle.Height + 4), // new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White), // 4 // ); //draw an animated dash around border of tile d2dContext.DrawRectangle( new RectangleF(_selectedRect.Rectangle.X - 2, _selectedRect.Rectangle.Y - 2, _selectedRect.Rectangle.Width + 4, _selectedRect.Rectangle.Height + 4), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.Yellow), 4, strokeStyle_dashed); //_drawTiles(_selectedRect.UniqueId); offsetSelectedDash++; if (offsetSelectedDash > 100) { offsetSelectedDash = 0; } } }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (BarsArray[0] == null || ChartBars == null) { return; } ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex]; float endX = panel.X + panel.W; if (ShowAskLine && ask != double.MinValue) { float startX = Convert.ToSingle(panel.X + panel.W * (1 - (AskLineLength / 100.0))); float y = chartScale.GetYByValue(ask); SharpDX.Direct2D1.StrokeStyleProperties strokeProperties = new SharpDX.Direct2D1.StrokeStyleProperties() { DashStyle = AskStroke.DashStyleDX }; using (SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(NinjaTrader.Core.Globals.D2DFactory, strokeProperties)) { RenderTarget.DrawLine(new SharpDX.Vector2(startX, y), new SharpDX.Vector2(endX, y), askBrush, AskStroke.Width, strokeStyle); } } if (ShowBidLine && bid != double.MinValue) { float startX = Convert.ToSingle(panel.X + panel.W * (1 - (BidLineLength / 100.0))); float y = chartScale.GetYByValue(bid); SharpDX.Direct2D1.StrokeStyleProperties strokeProperties = new SharpDX.Direct2D1.StrokeStyleProperties() { DashStyle = BidStroke.DashStyleDX }; using (SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(NinjaTrader.Core.Globals.D2DFactory, strokeProperties)) { RenderTarget.DrawLine(new SharpDX.Vector2(startX, y), new SharpDX.Vector2(endX, y), bidBrush, BidStroke.Width, strokeStyle); } } if (ShowLastLine && last != double.MinValue) { float startX = Convert.ToSingle(panel.X + panel.W * (1 - (LastLineLength / 100.0))); float y = chartScale.GetYByValue(last); SharpDX.Direct2D1.StrokeStyleProperties strokeProperties = new SharpDX.Direct2D1.StrokeStyleProperties() { DashStyle = LastStroke.DashStyleDX }; using (SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(NinjaTrader.Core.Globals.D2DFactory, strokeProperties)) { RenderTarget.DrawLine(new SharpDX.Vector2(startX, y), new SharpDX.Vector2(endX, y), lastBrush, LastStroke.Width, strokeStyle); } } }
/// <summary> /// 绘制刻度线 /// </summary> private void drawScale() { var brush = new SharpDX.Direct2D1.SolidColorBrush(cp._renderTarget, new RawColor4(0, 0, 1, 1)); var strokeStyleProperties = new SharpDX.Direct2D1.StrokeStyleProperties(); strokeStyleProperties.DashStyle = SharpDX.Direct2D1.DashStyle.Custom; float[] dashes = { 10, 5 }; var strokeStyle = new SharpDX.Direct2D1.StrokeStyle(cp.factory, strokeStyleProperties, dashes); foreach (var item in coordianteParamList) { foreach (var C in item.scalePointList) { cp._renderTarget.DrawLine(C.Item1, C.Item2, brush, item.LineWidth); //是否显示虚线 if (item.virtualLineVisible == VirtualLineVisible.Visible) { if (item.lineDirection == LineDireciton.Horizontal) { RawVector2 rv = new RawVector2(); rv.X = C.Item1.X; rv.Y = C.Item1.Y - VLength; cp._renderTarget.DrawLine(C.Item1, rv, brush, 0.5F, strokeStyle); } else { if (item.lineLocation == LineLocation.Right) { RawVector2 rv = new RawVector2(); rv.X = C.Item1.X - HLength - item.Index * LineInterval; rv.Y = C.Item1.Y; cp._renderTarget.DrawLine(C.Item1, rv, brush, 0.5F, strokeStyle); } else { RawVector2 rv = new RawVector2(); rv.X = C.Item1.X + HLength; rv.Y = C.Item1.Y; cp._renderTarget.DrawLine(C.Item1, rv, brush, 0.5F, strokeStyle); } } } } } }
public void DrawLine(System.Drawing.Point p1, System.Drawing.Point p2, System.Drawing.Color LineColor, float LineWidth, System.Drawing.Drawing2D.DashStyle dashStyle) { SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties(); ssProps.StartCap = SharpDX.Direct2D1.CapStyle.Flat; ssProps.EndCap = SharpDX.Direct2D1.CapStyle.Flat; ssProps.DashOffset = 0.1f; switch (dashStyle) { case System.Drawing.Drawing2D.DashStyle.Dash: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash; break; case System.Drawing.Drawing2D.DashStyle.DashDot: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot; break; case System.Drawing.Drawing2D.DashStyle.DashDotDot: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot; break; case System.Drawing.Drawing2D.DashStyle.Dot: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot; break; case System.Drawing.Drawing2D.DashStyle.Solid: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid; break; } SharpDX.Direct2D1.StrokeStyle LineStyle = new SharpDX.Direct2D1.StrokeStyle(D2Drender.Factory, ssProps); D2Drender.DrawLine(utils.Point2Raw(p1), utils.Point2Raw(p2), utils.SoildBrush2Raw(LineColor), LineWidth, LineStyle); }
// Condense Line drawing code private void DrawLine(string brushName, double x1, double y1, double x2, double y2, float width, DashStyleHelper dashStyle) { // Create StrokeStyleProperties SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties(); // Set StrokeStyleProperties Dashstyle to that of the DashStyleHelper if (dashStyle == DashStyleHelper.Dash) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash; } if (dashStyle == DashStyleHelper.DashDot) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot; } if (dashStyle == DashStyleHelper.DashDotDot) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot; } if (dashStyle == DashStyleHelper.Dot) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot; } if (dashStyle == DashStyleHelper.Solid) { ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid; } // Create StrokeStyle from StrokeStyleProperties SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFactory, ssProps); // Create Vector2 coordinates SharpDX.Vector2 startPoint = new System.Windows.Point(x1, y1).ToVector2(); SharpDX.Vector2 endPoint = new System.Windows.Point(x2, y2).ToVector2(); // Draw the line RenderTarget.DrawLine(startPoint, endPoint, dxmBrushes[brushName].DxBrush, width, strokeStyle); // StrokeStyle is device-independant and does not need to be Disposed after each OnRender() or OnRenderTargetChanged() call, but is for good housekeeping, strokeStyle.Dispose(); }
public void DrawPathGeometrySink(List <System.Drawing.Point> Points, System.Drawing.Color LineColor, float LineWidth, System.Drawing.Drawing2D.DashStyle dashStyle, bool CloseGeometry = false) { SharpDX.Direct2D1.PathGeometry pg = new SharpDX.Direct2D1.PathGeometry(D2Drender.Factory); SharpDX.Direct2D1.GeometrySink sink = pg.Open(); for (int i = 0; i < Points.Count; i++) { if (i == 0) { sink.BeginFigure(utils.Point2Raw(Points[0]), SharpDX.Direct2D1.FigureBegin.Hollow); } else { sink.AddLine(utils.Point2Raw(Points[i])); } } if (Points.Count > 0) { sink.EndFigure(CloseGeometry?SharpDX.Direct2D1.FigureEnd.Closed:SharpDX.Direct2D1.FigureEnd.Open); } sink.Close(); SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties(); ssProps.StartCap = SharpDX.Direct2D1.CapStyle.Flat; ssProps.EndCap = SharpDX.Direct2D1.CapStyle.Flat; ssProps.DashOffset = 0.1f; switch (dashStyle) { case System.Drawing.Drawing2D.DashStyle.Dash: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash; break; case System.Drawing.Drawing2D.DashStyle.DashDot: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot; break; case System.Drawing.Drawing2D.DashStyle.DashDotDot: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot; break; case System.Drawing.Drawing2D.DashStyle.Dot: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot; break; case System.Drawing.Drawing2D.DashStyle.Solid: ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid; break; } SharpDX.Direct2D1.StrokeStyle LineStyle = new SharpDX.Direct2D1.StrokeStyle(D2Drender.Factory, ssProps); D2Drender.DrawGeometry(pg, utils.SoildBrush2Raw(LineColor), LineWidth, LineStyle); }
/// <unmanaged>HRESULT ID2D1CommandSink::DrawGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged> public void DrawGeometry(SharpDX.Direct2D1.Geometry geometry, SharpDX.Direct2D1.Brush brush, float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle) { DrawGeometry_(geometry, brush, strokeWidth, strokeStyle); }
/// <unmanaged>HRESULT ID2D1CommandSink::DrawLine([In] D2D_POINT_2F point0,[In] D2D_POINT_2F point1,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged> public void DrawLine(SharpDX.Vector2 point0, SharpDX.Vector2 point1, SharpDX.Direct2D1.Brush brush, float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle) { DrawLine_(point0, point1, brush, strokeWidth, strokeStyle); }
/// <unmanaged>HRESULT ID2D1CommandSink::DrawRectangle([In] const D2D_RECT_F* rect,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged> public void DrawRectangle(SharpDX.RectangleF rect, SharpDX.Direct2D1.Brush brush, float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle) { DrawRectangle_(rect, brush, strokeWidth, strokeStyle); }
private void DirectXRender(List<UIElement> points) { if (points.Count <= 0) return; Line initLine = points[0] as Line; Point p1 = new Point ( Math.Min(initLine.X1 - initLine.StrokeThickness / 2, initLine.X2 - initLine.StrokeThickness / 2), Math.Min(initLine.Y1 - initLine.StrokeThickness / 2, initLine.Y2 - initLine.StrokeThickness / 2) ), p2 = new Point ( Math.Max(initLine.X1 + initLine.StrokeThickness / 2, initLine.X2 + initLine.StrokeThickness / 2), Math.Max(initLine.Y1 + initLine.StrokeThickness / 2, initLine.Y2 + initLine.StrokeThickness / 2) ); foreach (var child in points) { var line = child as Line; if (line == null) continue; if (p1.X > line.X1 - line.StrokeThickness / 2) p1.X = line.X1 - line.StrokeThickness / 2; if (p1.X > line.X2 - line.StrokeThickness / 2) p1.X = line.X2 - line.StrokeThickness / 2; if (p2.X < line.X1 + line.StrokeThickness / 2) p2.X = line.X1 + line.StrokeThickness / 2; if (p2.X < line.X2 + line.StrokeThickness / 2) p2.X = line.X2 + line.StrokeThickness / 2; if (p1.Y > line.Y1 - line.StrokeThickness / 2) p1.Y = line.Y1 - line.StrokeThickness / 2; if (p1.Y > line.Y2 - line.StrokeThickness / 2) p1.Y = line.Y2 - line.StrokeThickness / 2; if (p2.Y < line.Y1 + line.StrokeThickness / 2) p2.Y = line.Y1 + line.StrokeThickness / 2; if (p2.Y < line.Y2 + line.StrokeThickness / 2) p2.Y = line.Y2 + line.StrokeThickness / 2; } var bndRect = new Rect(p1, p2); var dxTarget = new SurfaceImageSource ( (int)(bndRect.Width * DisplayProperties.LogicalDpi / 96.0 + 1), (int)(bndRect.Height * DisplayProperties.LogicalDpi / 96.0 + 1) ); SharpDX.DXGI.ISurfaceImageSourceNative dxTargetNative = SharpDX.ComObject.As<SharpDX.DXGI.ISurfaceImageSourceNative>(dxTarget); dxTargetNative.Device = d3dDevice.QueryInterface<SharpDX.DXGI.Device>(); /* * Draw Logic */ SharpDX.DrawingPoint drawingPoint; var surface = dxTargetNative.BeginDraw(new SharpDX.Rectangle(0, 0, (int)(bndRect.Width * DisplayProperties.LogicalDpi / 96.0 + 1), (int)(bndRect.Height * DisplayProperties.LogicalDpi / 96.0 + 1)), out drawingPoint); var dxRenderTarget = new SharpDX.Direct2D1.RenderTarget(d2dFactory, surface, new SharpDX.Direct2D1.RenderTargetProperties() { DpiX = DisplayProperties.LogicalDpi, DpiY = DisplayProperties.LogicalDpi, PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), Type = SharpDX.Direct2D1.RenderTargetType.Default, Usage = SharpDX.Direct2D1.RenderTargetUsage.None }); dxRenderTarget.BeginDraw(); dxRenderTarget.Clear(SharpDX.Color.Transparent); foreach (var child in points) { var line = child as Line; if (line == null) continue; Color c = (line.Stroke as SolidColorBrush).Color; var brush = new SharpDX.Direct2D1.SolidColorBrush(dxRenderTarget, new SharpDX.Color(c.R, c.G, c.B, c.A)); var style = new SharpDX.Direct2D1.StrokeStyleProperties(); style.LineJoin = SharpDX.Direct2D1.LineJoin.Round; style.StartCap = SharpDX.Direct2D1.CapStyle.Round; style.EndCap = SharpDX.Direct2D1.CapStyle.Round; var stroke = new SharpDX.Direct2D1.StrokeStyle(d2dFactory, style); dxRenderTarget.DrawLine( new SharpDX.DrawingPointF((float)(line.X1 - bndRect.Left), (float)(line.Y1 - bndRect.Top)), new SharpDX.DrawingPointF((float)(line.X2 - bndRect.Left), (float)(line.Y2 - bndRect.Top)), brush, (float)line.StrokeThickness, stroke); } dxRenderTarget.EndDraw(); dxTargetNative.EndDraw(); var dxImage = new Image(); dxImage.Source = dxTarget; canvas.Children.Add(dxImage); Canvas.SetLeft(dxImage, bndRect.X); Canvas.SetTop(dxImage, bndRect.Y); }
private void _drawSelectedTile(SharpDX.Direct2D1.DeviceContext d2dContext) { if (_selectedRect != null) { var strokeStyle_dashed = new SharpDX.Direct2D1.StrokeStyle(d2dContext.Factory, new SharpDX.Direct2D1.StrokeStyleProperties() { DashOffset = (offsetSelectedDash / 5), DashStyle = SharpDX.Direct2D1.DashStyle.Dash }); ////drown out the shadow of the tile //d2dContext.DrawRectangle( // new RectangleF(_selectedRect.Rectangle.X - 2, _selectedRect.Rectangle.Y - 2, _selectedRect.Rectangle.Width + 4, _selectedRect.Rectangle.Height + 4), // new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White), // 4 // ); //draw an animated dash around border of tile d2dContext.DrawRectangle( new RectangleF(_selectedRect.Rectangle.X - 2, _selectedRect.Rectangle.Y - 2, _selectedRect.Rectangle.Width + 4, _selectedRect.Rectangle.Height + 4), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.Yellow), 4, strokeStyle_dashed); //_drawTiles(_selectedRect.UniqueId); offsetSelectedDash++; if (offsetSelectedDash > 100) offsetSelectedDash = 0; } }
/// <summary> /// Widens the geometry by the specified stroke and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> after it has been transformed by the specified matrix and flattened using the specified tolerance. /// </summary> /// <param name="strokeWidth">The amount by which to widen the geometry.</param> /// <param name="strokeStyle">The style of stroke to apply to the geometry, or NULL.</param> /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.</param> /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the widened geometry is appended.</param> /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns> /// <unmanaged>HRESULT Widen([None] FLOAT strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged> public void Widen(float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle, float flatteningTolerance, GeometrySink geometrySink) { this.Widen(strokeWidth, strokeStyle, null, flatteningTolerance, geometrySink); }
private void DirectXRender(List <UIElement> points) { if (points.Count <= 0) { return; } Line initLine = points[0] as Line; Point p1 = new Point ( Math.Min(initLine.X1 - initLine.StrokeThickness / 2, initLine.X2 - initLine.StrokeThickness / 2), Math.Min(initLine.Y1 - initLine.StrokeThickness / 2, initLine.Y2 - initLine.StrokeThickness / 2) ), p2 = new Point ( Math.Max(initLine.X1 + initLine.StrokeThickness / 2, initLine.X2 + initLine.StrokeThickness / 2), Math.Max(initLine.Y1 + initLine.StrokeThickness / 2, initLine.Y2 + initLine.StrokeThickness / 2) ); foreach (var child in points) { var line = child as Line; if (line == null) { continue; } if (p1.X > line.X1 - line.StrokeThickness / 2) { p1.X = line.X1 - line.StrokeThickness / 2; } if (p1.X > line.X2 - line.StrokeThickness / 2) { p1.X = line.X2 - line.StrokeThickness / 2; } if (p2.X < line.X1 + line.StrokeThickness / 2) { p2.X = line.X1 + line.StrokeThickness / 2; } if (p2.X < line.X2 + line.StrokeThickness / 2) { p2.X = line.X2 + line.StrokeThickness / 2; } if (p1.Y > line.Y1 - line.StrokeThickness / 2) { p1.Y = line.Y1 - line.StrokeThickness / 2; } if (p1.Y > line.Y2 - line.StrokeThickness / 2) { p1.Y = line.Y2 - line.StrokeThickness / 2; } if (p2.Y < line.Y1 + line.StrokeThickness / 2) { p2.Y = line.Y1 + line.StrokeThickness / 2; } if (p2.Y < line.Y2 + line.StrokeThickness / 2) { p2.Y = line.Y2 + line.StrokeThickness / 2; } } var bndRect = new Rect(p1, p2); var dxTarget = new SurfaceImageSource ( (int)(bndRect.Width * DisplayProperties.LogicalDpi / 96.0 + 1), (int)(bndRect.Height * DisplayProperties.LogicalDpi / 96.0 + 1) ); SharpDX.DXGI.ISurfaceImageSourceNative dxTargetNative = SharpDX.ComObject.As <SharpDX.DXGI.ISurfaceImageSourceNative>(dxTarget); dxTargetNative.Device = d3dDevice.QueryInterface <SharpDX.DXGI.Device>(); /* * Draw Logic */ SharpDX.DrawingPoint drawingPoint; var surface = dxTargetNative.BeginDraw(new SharpDX.Rectangle(0, 0, (int)(bndRect.Width * DisplayProperties.LogicalDpi / 96.0 + 1), (int)(bndRect.Height * DisplayProperties.LogicalDpi / 96.0 + 1)), out drawingPoint); var dxRenderTarget = new SharpDX.Direct2D1.RenderTarget(d2dFactory, surface, new SharpDX.Direct2D1.RenderTargetProperties() { DpiX = DisplayProperties.LogicalDpi, DpiY = DisplayProperties.LogicalDpi, PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), Type = SharpDX.Direct2D1.RenderTargetType.Default, Usage = SharpDX.Direct2D1.RenderTargetUsage.None }); dxRenderTarget.BeginDraw(); dxRenderTarget.Clear(SharpDX.Color.Transparent); foreach (var child in points) { var line = child as Line; if (line == null) { continue; } Color c = (line.Stroke as SolidColorBrush).Color; var brush = new SharpDX.Direct2D1.SolidColorBrush(dxRenderTarget, new SharpDX.Color(c.R, c.G, c.B, c.A)); var style = new SharpDX.Direct2D1.StrokeStyleProperties(); style.LineJoin = SharpDX.Direct2D1.LineJoin.Round; style.StartCap = SharpDX.Direct2D1.CapStyle.Round; style.EndCap = SharpDX.Direct2D1.CapStyle.Round; var stroke = new SharpDX.Direct2D1.StrokeStyle(d2dFactory, style); dxRenderTarget.DrawLine( new SharpDX.DrawingPointF((float)(line.X1 - bndRect.Left), (float)(line.Y1 - bndRect.Top)), new SharpDX.DrawingPointF((float)(line.X2 - bndRect.Left), (float)(line.Y2 - bndRect.Top)), brush, (float)line.StrokeThickness, stroke); } dxRenderTarget.EndDraw(); dxTargetNative.EndDraw(); var dxImage = new Image(); dxImage.Source = dxTarget; canvas.Children.Add(dxImage); Canvas.SetLeft(dxImage, bndRect.X); Canvas.SetTop(dxImage, bndRect.Y); }