http://marakana.com/tutorials/android/2d-graphics-example.html
我正在使用下面的示例,但当我在屏幕上快速移动手指时,线条会变成单个点。
我不确定是否可以加速绘制。或者我应该用一条直线连接最后两个点。这两种解决方案中的第二个似乎是一个不错的选择,除非您在移动手指时非常快,则会出现长时间的直线段和锐角曲线。
如果有其他解决方案,很高兴听到他们的意见。
谢谢提前帮助。
http://marakana.com/tutorials/android/2d-graphics-example.html
我正在使用下面的示例,但当我在屏幕上快速移动手指时,线条会变成单个点。
我不确定是否可以加速绘制。或者我应该用一条直线连接最后两个点。这两种解决方案中的第二个似乎是一个不错的选择,除非您在移动手指时非常快,则会出现长时间的直线段和锐角曲线。
如果有其他解决方案,很高兴听到他们的意见。
谢谢提前帮助。
这里有一个简单的方法,可以平滑使用Path绘制的点。lineTo
fun applySmoothing(smoothingIterations: Int) {
for (z in 1..smoothingIterations) {
for (i in graphPoints.indices) {
if (i > 0 && i < graphPoints.size-1) {
val previousPoint = graphPoints[i-1]
val currentPoint = graphPoints[i]
val nextPoint = graphPoints[i+1]
val midX = (previousPoint.x + currentPoint.x + nextPoint.x) / 3
val midY = (previousPoint.y + currentPoint.y + nextPoint.y) / 3
graphPoints[i].x = midX
graphPoints[i].y = midY
}
}
}
}
Path.quadTo
,Path.cubicTo
... https://dev59.com/IVDTa4cB1Zd3GeqPL8aU - HostileFork says dont trust SE