我有一个像“paint”这样的简单应用程序,我在设置为 pictureBox.Image
的位图中绘制。我可以在这里绘制多边形并将它们捕捉到顶点并移动,因此必须重新绘制位图。
有repaint方法。
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);
}
}
因此,如果我捕捉到顶点并移动鼠标,DrawFullList()
函数将在 pictureBox_MouseMove(object sender, MouseEventArgs e)
函数中激活。当我移动一个顶点几秒钟(例如,制作圆圈)时,系统.Drawing.dll 中发生的异常 'System.ArgumentException'
被抛出。
这里有什么提示吗? :)
编辑:
有关异常的其他信息:
参数无效
最佳答案
您应该从 g - g.dispose()
释放内存。内存不足会导致此类异常,因为您的 bmp 可能对于实际可用内存来说太大了。
关于c# - System.Drawing.dll 中出现“System.ArgumentException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36630669/