-
September 29th, 2011, 03:11 AM
#1
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();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|