我正试着快速地在屏幕上画出很多点.我创建了以下方法.
void _paintPoints(Canvas canvas, List matrix, Size size) {
final width = size.width / matrix.length;
final height = size.height / matrix.first.length;
Float32List points = Float32List(matrix.length * matrix.length * 2);
final pointColors = <Color>[];
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix[i].length; j++) {
final x = i * width;
final y = j * height;
final index = (i * matrix.length + j) * 2;
points[index] = x;
points[index + 1] = y;
Color color = Color.fromARGB(
matrix[i][j][3], matrix[i][j][0], matrix[i][j][1], matrix[i][j][2]);
pointColors.add(color);
}
}
canvas.drawRawPoints(
PointMode.points,
points,
paint
..blendMode = BlendMode.srcOver
..strokeWidth = 2.0,
);
}
这种方法能够快速绘制点,但所有的点都是相同的 colored颜色 (不使用pointColors
).有没有办法用drawRawPoints()
或其他Canvas
方法用特定的 colored颜色 快速画出很多点(几万个)?
我试着把每个点分开画,但太慢了.