blah blah blah is here! blah blah » Close

up0down
link

I need to find an efficient way to draw basic rectangles to a bitmap and have my PictureBox reflect that bitmap. As it stands I am drawing to the bitmap and my PictureBox reflects that image. However the drawing is super laggy; especially when you jerk the mouse across the canvas.

How can I fix this?

last answered 2 years ago

1 answers

link

OK, so I fixed the problem by drawing lines and filling in "bad" spots (happened when moving slowly) with circles. Here's the code:

private void PaintPoints()
{
try
{
for (int i = 1; i < _pointsToDraw.Count; i++)
{
_graphics = Graphics.FromImage(_project.Map.BMP);
_graphics.FillEllipse(new SolidBrush(_color), _pointsToDraw[i].X - (_brushSize / 2), _pointsToDraw[i].Y - (_brushSize / 2), _brushSize, _brushSize);
_graphics.DrawLine(new Pen(new SolidBrush(_color), _brushSize), _pointsToDraw[i - 1], _pointsToDraw[i]);
_graphics.Dispose();
canvas.Image = _project.Map.BMP;
canvas.Invalidate();
_pointsToDraw.RemoveAt(i - 1);
}
}
catch
{
PaintPoints();
}
finally
{
if (!Draw())
{
_pointsToDraw.Clear();
}
}
}

I should also mention that multi-threading is being used. Main thread creates points, second thread draws on top of them.

Feedback