Reputation: 377
I have simple application like "paint", I draw in a bitmap which is set to the pictureBox.Image
. I can draw here polygons and catch them on the vertices and move, so the bitmap must be repaint.
There is the repaint method.
private void DrawFullList()
{
if(pictureBox2.Image != null)
pictureBox2.Image.Dispose();
graphic = new Bitmap(pictureBox2.Width, pictureBox2.Height); // exception here
g = Graphics.FromImage(graphic);
pictureBox2.Image = graphic;
for (int i = 0; i < PointsList.Count; i++)
{
bool yellowframe = false;
if (i == dblclck)
yellowframe = true;
Draw(BrushList[i], PointsList[i], yellowframe);
}
}
So if I catch vertice and move mouse, the function DrawFullList()
is activated in the pictureBox_MouseMove(object sender, MouseEventArgs e)
function. When I move the one vertice for few second (for example, making circles) The exception 'System.ArgumentException' occurred in System.Drawing.dll
is thrown.
Any tips here? :)
Edit:
additional info about exception:
parameter is invalid
Upvotes: 3
Views: 8170
Reputation: 130
You should dispose from g - g.dispose()
to free memory. Lack of memory can cause such a exception because your bmp may be too big for actually free memory.
Upvotes: 4