我正在使用NGraphics,我希望生成一条平滑的曲线。
与使用以下代码的iPhone相比,Android设备显示的效果不同。
用星号(*)包围的线,如果在Android上使用(在三星Galaxy S4上测试),曲线看起来像预期的那样。但是,在iPhone上它看起来不正确。
private bool DrawingMove(TouchData touchData)
{
if (touchData == null)
{
Invalidate();
return true;
}
foreach (var stroke in _localStroke)
{
if (stroke.Pointer == touchData.PointerId)
{
var newPoint = ConvertLocalToGlobal(touchData.Point);
var point = new PointModel();
point.X = newPoint.X;
point.Y = newPoint.Y;
stroke.Points.Add(point);
var length = stroke.Points.Count - 1;
if (stroke.Points.Count >= 3)
{
var p1 = ConvertGlobalToLocal(
new Point(stroke.Points[length - 2].X,
stroke.Points[length - 2].Y));
var p2 = ConvertGlobalToLocal(
new Point(stroke.Points[length - 1].X,
stroke.Points[length - 1].Y));
var p3 = ConvertGlobalToLocal(
new Point(stroke.Points[length].X,
stroke.Points[length].Y));
if (stroke.Points.Count == 3)
{
stroke.Path.MoveTo(p1);
stroke.Path.CurveTo(p1, p2, p3);
}
else if (stroke.Points.Count > 3)
{
**stroke.Path.LineTo(p2);**
stroke.Path.ContinueCurveTo(p2, p3);
Console.WriteLine("Path.ContinueCurveTo(new Point(" + p2.X + "," + p2.Y + "),new Point(" + p3.X + "," + p3.Y + "));");
}
}
break;
}
}
return base.TouchesMoved(touchData);
}
上面的代码生成以下结果:
我还试图在没有上面所有触摸绘图代码的小样本中重现这一点,只需将坐标传递给CurveTo
和ContinueCurveTo
,就可以得到相同的结果。
答案 0 :(得分:0)
找到答案......刚刚意识到我必须传递当前点加上前一点并获得中间点。