InkCanvas绘制自定义形状(矩形)

时间:2017-01-20 11:20:35

标签: c# wpf inkcanvas

我像油漆一样创造程序。现在尝试创建标准形状。但我有绘制矩形的问题。我使用方法DrawCore在InkCanvas上创建自定义形状。

代码:

protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
    {
        if (drawingContext == null)
        {
            throw new ArgumentNullException("drawingContext");
        }
        if (null == drawingAttributes)
        {
            throw new ArgumentNullException("drawingAttributes");
        }
        DrawingAttributes originalDa = drawingAttributes.Clone();

        SolidColorBrush brush = new SolidColorBrush(color);
        System.Windows.Media.Pen pen = new System.Windows.Media.Pen(new SolidColorBrush(color), 1);

        brush.Freeze();


        drawingContext.DrawRectangle(null, pen, new Rect(GetTheLeftTopPoint(), GetTheRightBottomPoint()));

        }
}

    System.Windows.Point GetTheLeftTopPoint()
    {
        if (this.StylusPoints == null)
            throw new ArgumentNullException("StylusPoints");
        StylusPoint tmpPoint = new StylusPoint(double.MaxValue, double.MaxValue);
        foreach (StylusPoint point in this.StylusPoints)
        {
            if ((point.X < tmpPoint.X) || (point.Y < tmpPoint.Y))
                tmpPoint = point;
        }
        return tmpPoint.ToPoint();
    }

    System.Windows.Point GetTheRightBottomPoint()
    {
        if (this.StylusPoints == null)
            throw new ArgumentNullException("StylusPoints");
        StylusPoint tmpPoint = new StylusPoint(0, 0);
        foreach (StylusPoint point in this.StylusPoints)
        {
            if ((point.X > tmpPoint.X) || (point.Y > tmpPoint.Y))
                tmpPoint = point;
        }
        return tmpPoint.ToPoint();
    }

但我的问题是,我不能指出所有方向。那是: enter image description here

如何解决?

谢谢。

0 个答案:

没有答案