0

My question has three parts:
I Can draw shapes like line, Circle, Rectangle and .. on WPF Canvas. I want to use InkCanvas features like erasing and moving strokes.

  1. Is it possible to convert this shape to a collection of stylus points and add this collection to InkCanvas?
  2. If it's possible how can I do that?
  3. Is there a better approach to this situation?

Guide me please.

hemarn
  • 63
  • 1
  • 13

1 Answers1

2

first of all, the answer is Yes. you can convert paths to stroke collection and then add them to the InkCanvas.
For the second part of your question, the answer should be something like this:

Point mypoint;
Point tg;
var pointCollection = new List<Point>();
    for (var i = 0; i < 500; i++)
        {
           SomePath.Data.GetFlattenedGeometryPath()
                         .GetPointAtFractionLength(i / 500f, out mypoint, out tg);
            pointCollection.Add(p);
        }

For stylus point and stylus point collection:

 StylusPointCollection StPoints = new StylusPointCollection();

add stylus points during converting path to collection of points by:

 StPoints.Add(new StylusPoint(p.X, P.Y));

And after this step calling Stroke method to create a collection of strokes from your stylus collection:

Stroke st = null;
st = new Stroke(StPoints);

Update
Yes! there is a better ways for adding shapes to inkCanvas.

  1. You can define this stylus points shape directly and add them using MouseDown, MouseMove.. for example for drawing a Rectangle:

    pts.Add(new StylusPoint(mouseLeftDownPoint.X, mouseLeftDownPoint.Y));
    pts.Add(new StylusPoint(mouseLeftDownPoint.X, currentPoint.Y));
    pts.Add(new StylusPoint(currentPoint.X, currentPoint.Y));
    pts.Add(new StylusPoint(currentPoint.X, mouseLeftDownPoint.Y));
    pts.Add(new StylusPoint(mouseLeftDownPoint.X, mouseLeftDownPoint.Y));
    
  2. Or Override DrawCore method of Stroke Class and define a new stroke type. Custom Rendering Ink (MSDN)

hemarn
  • 63
  • 1
  • 13
  • 2
    Thanks:) I will try new methods. I thinks its very good idea to draw directly on Inkcanvas instead of converting paths. –  Aug 13 '17 at 12:03
  • 2
    Yes it is. as always saves some memory and processing and beside that stylus point does not support brazier points. – hemarn Aug 13 '17 at 12:06