CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2011
    Posts
    2

    How to use WPF to implement multi-pen drawing?

    At first I reference
    http://blogs.msdn.com/b/jaimer/archi...ultitouch.aspx # 9931447
    to implement multi-pen, but in the running, I found a noticeable delay between the touch point and the track, and using CPU resouces is very big.

    In inkcanvas in writing when there is no such single issue.inkcanvas's static handwriting and dynamic handwriting is separate. In multi-pen implementation , how can I implement this effect?

    public class Window2Panel : Panel
    {
    private VisualCollection _col;

    public Window2Panel()
    {
    _col = new VisualCollection(this);
    }

    protected override Visual GetVisualChild(int index)
    {
    return _col[index];
    }

    protected override int VisualChildrenCount
    {
    get
    {
    return _col.Count;
    }
    }

    bool down = false;

    CustomPen pen=null;
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
    down = true;
    pen = new CustomPen(e.GetPosition(this));
    _col.Add(pen);
    }

    protected override void OnMouseMove(MouseEventArgs e)
    {
    if (down && pen!=null)
    {
    pen.AddPoint(e.GetPosition(this));
    }
    }
    protected override void OnMouseUp(MouseButtonEventArgs e)
    {
    down = false;
    pen = null;
    }
    }

    public class CustomPen : DrawingVisual
    {
    private Stroke stroke;

    public CustomPen(Point point):this(new StylusPoint(point.X, point.Y))
    {
    }

    public CustomPen(StylusPoint point)
    {
    StylusPointCollection points = new StylusPointCollection();
    points.Add(point);
    stroke = new Stroke(points);
    }

    public void AddPoint(Point point)
    {
    this.AddPoint(new StylusPoint(point.X, point.Y));
    }

    public void AddPoint(StylusPoint point)
    {
    stroke.StylusPoints.Add(point);
    this.Draw();
    }

    private void Draw()
    {
    DrawingContext dc = this.RenderOpen();
    stroke.Draw(dc);
    dc.Close();
    }
    }

  2. #2
    Join Date
    Sep 2011
    Posts
    2

    Re: How to use WPF to implement multi-pen drawing?

    Here are two examples can be run, using VS2008 and. Net FrameWork3.0。
    https://skydrive.live.com/redir.aspx...6DA8D15AEE!103
    Delay example, the longer the draw, between the mouse and lines will be a very significant delay (after the mouse to stop, delay disappeared), and CPU utilization much, mainly because of the mouse each take a sampling point, we need to re-draw the lines;Non-delayed example you will find that handwriting is very smooth, although take up memory, but not as good as the first clear, the key is not that obvious delay.
    My aim is to achieve multi-pen, refers to more than one person can use the stylus on the touch pad or finger free writing, which requires hardware support. Currently there is no hardware problem, the problem is a multi-pen when the delay is not significant (due to hardware limitations, there will be some delay in itself).
    Examples of the use of delayed implementation, to achieve multi-pen, but the process caused the delay with the hardware itself, and do not make people suffer; example if the non-delay multiple ways to achieve freedom of writing, then, is an ideal, but I can not find how to DynamicRenderer the RootVisual simultaneously display different handwriting method.
    What should I do here? how achieve multi-pen? Are there other ways? Please help me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured