简体   繁体   English

如何使用 InkStroke 绘制圆?

[英]How can I draw a Circle with InkStroke?

I have an InkCanvas.我有一个 InkCanvas。 I need to a Circle draw as InkStroke.我需要将圆形绘制为 InkStroke。

I know, i can a Circle or Ellipse draw with InkAnalyzer, but i need that Circle as InkStroke in InkCanvas, not in Canvas and i don't want to the protractor use.我知道,我可以使用 InkAnalyzer 绘制圆形或椭圆形,但我需要该圆形作为 InkCanvas 中的 InkStroke,而不是 Canvas,我不想使用量角器。

I need somehow a right one Circle draw.我需要以某种方式进行一次正确的圈画。

For a straight Line developed i this code;对于这条代码开发的直线;

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;
} 

How can i this Code to adjust for a Circle?我如何将此代码调整为圆? Or how can i draw a Circle?或者我怎样才能画一个圆圈?

Thank you,谢谢,

If I understood your question correctly, you just want to use InkStroke to draw a ellipse and add these strokes of ellipse into InkCanvas.如果我正确理解您的问题,您只想使用 InkStroke 绘制一个椭圆并将这些椭圆的笔触添加到 InkCanvas 中。 Then, you could get use these strokes for other purposes (eg, save these strokes and use it for the next usage).然后,您可以将这些笔画用于其他目的(例如,保存这些笔画并在下次使用时使用)。 If so, I could only tell you it's impossible.如果是这样,我只能告诉你这是不可能的。 Because when you draw a similar ellipse on InkCanvas, you could use InkAnalyzer to convert it to ellipse, but it actually only returns four points to you.因为当你在 InkCanvas 上画一个类似的椭圆时,你可以用 InkAnalyzer 把它转换成椭圆,但它实际上只返回四个点给你。 Jayden also has mentioned it on this thread: Add polygon/ellipse to inkcanvas in uwp Jayden 在此线程中也提到了它: 在 uwp 中将多边形/椭圆添加到inkcanvas

But as I said, if the reason of using inkstroke to draw ellipse is to save strokes for other purposes, I can give you another way.但是正如我所说,如果使用inkstroke绘制椭圆的原因是为了节省笔触用于其他目的,我可以给你另一种方式。 You could use win2D-UWP relevant APIs to draw ellipse on CanvasControl and save it as CanvasSvgDocument.您可以使用win2D-UWP相关 API 在 CanvasControl 上绘制椭圆并将其保存为 CanvasSvgDocument。 Then, you could save it as a svg xml file.然后,您可以将其另存为 svg xml 文件。 For the net usage, you could load this svg xml file by CanvasSvgDocument.LoadAsync into CanvasControl.对于网络使用,您可以通过CanvasSvgDocument.LoadAsync将此 svg xml 文件CanvasSvgDocument.LoadAsync到 CanvasControl 中。

If you're interested in CanvasSvgDocument, you could refer to SvgExample for more details.如果您对 CanvasSvgDocument 感兴趣,可以参考SvgExample了解更多详细信息。

在此处输入图片说明

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
}

If you want lines instead of dots, draw a line from the previous xy to the current xy.如果您想要线条而不是点,请从前一个 xy 到当前 xy 画一条线。 (cache xy in xy_old) (在 xy_old 中缓存 xy)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM