我需要从二维数组中绘制大约250'000个具有不同颜色的点。我正在尝试使用SurfaceView做到这一点。它运作良好,但是绘制需要2-3秒(我正在寻找“开始绘制” /“绘制完成”日志记录之间的时间)。可能我选择了错误的方式或做错了事。在Android中获得25万点的最佳性能是什么?
这是我的代码:
class MyDrawThread(private val surfaceHolder: SurfaceHolder) : Thread() {
var isRunning = false
var points: List<List<Int>>? = null
override fun run() {
var canvas: Canvas?
while (isRunning) {
points?.let { points ->
canvas = null
try {
Log.d(TAG, "Start draw")
canvas = surfaceHolder.lockCanvas(null)
synchronized(surfaceHolder) {
canvas!!.drawColor(Color.BLACK)
for ((x, list) in points.withIndex()) {
val paint = Paint()
for ((y, colorId) in list.withIndex()) {
paint.color = getColor(colorId) // Get color from hardcoded array by index
canvas!!.drawPoint(x.toFloat(), y.toFloat(), paint)
}
}
}
} finally {
surfaceHolder.unlockCanvasAndPost(canvas)
Log.d(TAG, "Draw done")
}
}
Thread.sleep(10000L)
}
}
}