【问题标题】:'System.ArgumentException' occurred in System.Drawing.dllSystem.Drawing.dll 中发生“System.ArgumentException”
【发布时间】:2016-08-06 10:53:40
【问题描述】:

我有一个简单的应用程序,比如“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) 函数中被激活。当我移动一个顶点几秒钟(例如,制作圆圈)时,抛出异常'System.ArgumentException' occurred in System.Drawing.dll。 这里有什么提示吗? :)

编辑: 有关异常的附加信息: parameter is invalid

【问题讨论】:

  • 是否有特定的消息伴随它?
  • 参数无效
  • 无效值的值是多少?你打破例外吗?询问价值,看看它不喜欢什么。
  • 宽度 = 1328,高度 = 1162;但是位图的大小在移动顶点期间没有改变,并且它在几秒钟内正确创建。

标签: c# winforms


【解决方案1】:

您应该从 g - g.dispose() 释放内存。内存不足可能会导致此类异常,因为您的 bmp 可能太大而无法实际释放内存。

【讨论】:

  • 谢谢!这个对我有用。花了很多时间寻找解决方案,想如果我从图片框中释放图像,这也是免费的:))
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 2017-12-09
  • 2016-05-29
  • 1970-01-01
相关资源
最近更新 更多