如何使用InkStroke进行圆形绘制?

时间:2017-11-24 09:07:26

标签: c# uwp geometry stroke inkcanvas

我有一个InkCanvas。我需要将Circle绘制为InkStroke。

  

我知道,我可以使用InkAnalyzer绘制圆形或椭圆形,但我需要   这个Circle作为InkCanvas中的InkStroke,而不是Canvas,我不想   量角器使用。

我需要一个正确的圆形画。

对于直线开发我的代码;

private void StrokeInput_StrokeEnded(InkStrokeInput sender, PointerEventArgs args)
{
    List<InkPoint> points = new List<InkPoint>();
    InkStrokeBuilder builder = new InkStrokeBuilder();


    InkPoint pointOne = new InkPoint(new Point(line.X1, line.Y1), 0.5f);
    points.Add(pointOne);
    InkPoint pointTwo = new InkPoint(new Point(line.X2, line.Y2), 0.5f);
    points.Add(pointTwo);

    InkStroke stroke = builder.CreateStrokeFromInkPoints(points, System.Numerics.Matrix3x2.Identity);
    InkDrawingAttributes ida = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
    stroke.DrawingAttributes = ida;
    inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);

}

private void StrokeInput_StrokeContinued(InkStrokeInput sender, PointerEventArgs args)
{
    line.X2 = args.CurrentPoint.RawPosition.X;
    line.Y2 = args.CurrentPoint.RawPosition.Y;
}

private void StrokeInput_StrokeStarted(InkStrokeInput sender, PointerEventArgs args)
{
    line = new Line();
    line.X1 = args.CurrentPoint.RawPosition.X;
    line.Y1 = args.CurrentPoint.RawPosition.Y;
    line.X2 = args.CurrentPoint.RawPosition.X;
    line.Y2 = args.CurrentPoint.RawPosition.Y;

    line.Stroke = new SolidColorBrush(Colors.Purple);
    line.StrokeThickness = 4;
} 

我如何为圆圈调整此代码?或者我怎么画圆圈?

谢谢,

1 个答案:

答案 0 :(得分:0)

float stepsize = 0.05f;
float radius = 10f;

for (float i = 0; i <= 2*Math.PI; i+= stepsize )

  var x = position.x + radius * Math.cos(i);
  var y = position.y + radius * Math.sin(i);
  // draw dot here at x,y
}

如果想要线而不是点,请从前一个xy到当前xy绘制一条线。 (在xy_old中缓存xy)