I am trying to draw a lot of points to the screen quickly. I have created the following method.
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,
);
}
This method is able to draw the points quickly but all of the points are the same color (The pointColors
are not used). Is there away to use drawRawPoints()
or some other Canvas
method to draw a lot of points (tens of thousands) quickly with specific colors?
I have tried drawing each point separately, but it was too slow.