相关疑难解决方法(0)

不使用所有内存/限制时内存不足

我们在这里有一个问题,我们可以有一些问题OutOfMemoryException.

我们将检查如何减少内存使用量,但我的问题是为什么我在这一点上得到它.

根据Memory Profiler和Windows任务管理器,应用程序的权重仅为 400MB.

对于我所理解的(在此确认),对于32位应用程序,限制应该在2GB左右.我的电脑有16GB的内存,并且有足够的内存(超过4GB).

那我为什么现在得到这个错误呢?

我的问题不是为什么我的应用程序的内存增长,而是更多地了解为什么它现在已经发生了.我觉得这个限制不是固定的,但我找不到任何参考.

调用堆栈如果有帮助:

System.OutOfMemoryException: Out of memory.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   at Nevron.GraphicsCore.NBitmapGdiRenderSurface.Paint(Object sender, PaintEventArgs e, l1ll11Il1 contentPainter)
   at Nevron.Chart.WinForm.NControlView.Paint(Object sender, PaintEventArgs e)
   at Nevron.Chart.WinForm.NChartControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Run Code Online (Sandbox Code Playgroud)

编辑 我得到了完全不同的堆栈跟踪相同的异常:

System.ComponentModel.Win32Exception (0x80004005): Not …
Run Code Online (Sandbox Code Playgroud)

.net c# memory-leaks memory-management out-of-memory

1
推荐指数
1
解决办法
1018
查看次数

将Bitmap的内容粘贴到PictureBox中

我目前正在编写一个小型绘图应用程序,用户可以在Panel上绘图.我正在使用选择工具,并希望能够选择面板的某个区域,然后将此选定区域直接粘贴到我刚刚在Panel右侧的PictureBox中.

我的问题是我的代码目前无法正常工作,当我尝试从面板粘贴我正在创建的Bitmap时,我在PictureBox中获得了一个大的红色X而不是实际的图像.我知道图像正在正确地复制到Bitmap,因为我尝试在它周围放一些代码将它作为jpeg保存到磁盘,然后查看图像,它显示正常.

这是我的代码:

private void tbCopy_Click(object sender, EventArgs e)
{
    int width = selectList[0].getEnd().X - selectList[0].getInitial().X;
    int height = selectList[0].getEnd().Y - selectList[0].getInitial().Y;

    using (Bitmap bmp = new Bitmap(width, height))
    {
        pnlDraw.DrawToBitmap(bmp, new System.Drawing.Rectangle(
                                      selectList[0].getInitial().X,
                                      selectList[0].getInitial().Y, 
                                      width, height));
        pbPasteBox.Image = bmp;             
    }
}   
Run Code Online (Sandbox Code Playgroud)

宽度和高度只是我要复制的区域的尺寸,而selectList是一个包含一个对象的List,其中包含我要复制的区域的坐标.

任何帮助将不胜感激.

c# copy bitmap paste picturebox

0
推荐指数
1
解决办法
1365
查看次数