将鼠标单击与曲线结合并形成形状 [英] Joining the Mouse clicks with curves and forming shapes
问题描述
你好,
我正在中介中显示图像.
现在,如果我单击图像并选择绘制形状"按钮,则单击的位置应合并并形成形状.在这里,我使用Quadraticbezier曲线来吸引点击.
当我做奇怪的时候.点击图片并选择绘制形状.形状非常完美,但是如果我不这样做的话.的点击次数曲线是在不连接起点和终点的情况下形成的.
为什么会发生这种情况,请问iam哪里出了错
代码:
Hello,
I am displaying the images in mediaelement.
Now if i do clicks on the image and select draw shape button the clicked positions should join and form a shape. here iam using Quadraticbezier curves for joing the mous clicks.
When i do odd no. of clicks on the image and select draw shape. the shape is coming perfectly but if i do even no. of clicks the curve is forming without joining the starting point and ending point.
why is this happening plz any find where iam going wrong
code:
void Mediaelement1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
checkPoints.Add(Mouse.GetPosition(mediaelement1));
}
Drawshape按钮代码:
Drawshape button code:
SolidColorBrush bgBrush = new SolidColorBrush();
bgBrush.Color = Colors.Transparent;
SolidColorBrush borderBrush = new SolidColorBrush();
borderBrush.Color = Colors.Black;
Path polyPath = new Path();
polyPath.Stroke = borderBrush;
polyPath.StrokeThickness = 1;
polyPath.Fill = bgBrush;
GeometryGroup polyGeometryGroup = new GeometryGroup();
PathFigure pLineFigure = new PathFigure();
PolyQuadraticBezierSegment PQSegment=new PolyQuadraticBezierSegment ();
foreach(var itr in checkPoints)
{
PQSegment.Points.Add(itr);
}
PQSegment.Points.Add( checkPoints[0]);
Point startPoint= checkPoints[0];
pLineFigure.StartPoint = new Point(startPoint.X,startPoint.Y);
pLineFigure.Segments.Add( PQSegment);
PathGeometry pGeometry = new PathGeometry();
pGeometry.Figures.Add(pLineFigure);
polyGeometryGroup.Children.Add(pGeometry);
polyPath.Data = polyGeometryGroup;
this .mediasp.Children.Add (polyPath);
checkPoints.Clear();
}
请任何人解释为什么甚至没有.的点击不是形成形状时的起点和终点.
Plz anyone explain why even no. of clicks are not joininmg startpoint and end point while forming shape.
推荐答案
您是否尝试过在pLineFigure上设置IsClosed属性?有什么作用吗?所提供的代码中没有立即明显的原因引起您的问题
have you tried setting the IsClosed property on pLineFigure? does that have any effect. There is no immediately obvious cause for your problem in the code supplied
这篇关于将鼠标单击与曲线结合并形成形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!