2011-06-17 37 views
2

我正在用Streamgeometry来新绘制一个简单的箭头。现在我需要将箭头转到指定的角度。但如何旋转这个几何?旋转几何路径

Dim pt1 As New Point(X1, Me.Y1) 'left point 
Dim pt2 As New Point(_X2, Me.Y2) 'right point 

Dim pt3 As New Point(_X2 + (HeadWidth * cost - HeadHeight * sint), Y2 + (HeadWidth * sint + HeadHeight * cost)) 'arrow line down 
Dim pt4 As New Point(_X2 + (HeadWidth * cost + HeadHeight * sint), Y2 - (HeadHeight * cost - HeadWidth * sint)) 'arrow line up 

context.BeginFigure(pt1, True, False) 
context.LineTo(pt2, True, True) 
context.LineTo(pt3, True, True) 
context.LineTo(pt2, True, True) 
context.LineTo(pt4, True, True) 

回答

3

如果旋转仅用于演示(即你不关心原始几何数据仍然在原来的方向指向的箭头),那么你可以申请一个transform它。

你画在你的背景后,只要应用改造原有StreamGeometry对象(代码在C#中,但它适用于VB.NET太):

var geo = new StreamGeometry(); 
using (var ctx = geo.Open()) 
{ 
    ctx.BeginFigure(new Point(0, 20), false, false); 
    ctx.LineTo(new Point(100, 20), true, true); 
    ctx.LineTo(new Point(80, 40), true, true); 
    ctx.LineTo(new Point(80, 0), true, true); 
    ctx.LineTo(new Point(100, 20), true, true); 
} 
geo.Transform = new RotateTransform(45); 
var drawing = new GeometryDrawing(Brushes.Transparent, new Pen(Brushes.Black, 1), geo); 
image1.Source = new DrawingImage(drawing); 

上面的代码将会画一个箭头在名为image1Image控件上向下/向右指向。

+0

感谢您的回答。我尝试过,但如果我像你所建议的那样使用Rotatetransform来创建几何体,那么它就不会起作用。我不知道为什么。 – Nasenbaer 2011-06-17 12:44:33