Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OutOfMemoryException未处理_C#_Bitmap_Out Of Memory_System.drawing - Fatal编程技术网

C# OutOfMemoryException未处理

C# OutOfMemoryException未处理,c#,bitmap,out-of-memory,system.drawing,C#,Bitmap,Out Of Memory,System.drawing,我将应用程序更改为缝合多个文件。 我在btnDoItAll代码中放置了一个for循环,循环将取决于要缝合的图像数量。 我在循环结束时加入了裁剪代码。您可以看到。 出现了一个错误,该错误表示OutOfMemoryException未处理-此部分内存不足 croppedBitmap = croppedBitmap.Clone(new Rectangle(MinWidth, 0, (int)croppedBitmap.Width - MinWidth - MaxWidth, 1323), System

我将应用程序更改为缝合多个文件。
我在
btnDoItAll
代码中放置了一个
for循环
,循环将取决于要缝合的图像数量。
我在循环结束时加入了裁剪代码。您可以看到。
出现了一个错误,该错误表示
OutOfMemoryException未处理-此部分内存不足

croppedBitmap = croppedBitmap.Clone(new Rectangle(MinWidth, 0, (int)croppedBitmap.Width - MinWidth - MaxWidth, 1323), System.Drawing.Imaging.PixelFormat.DontCare);
希望你能再次帮助我

The output from debug was these:  
Bitmap-width: 877
Bitmap-height: 1325
Width: -1
MinWidth: 877
A first chance exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll  

几个小时前我遇到了一个类似的问题,检查你的克隆边界。如果移动到位图之外,它将引发此异常

所以要小心,情况就是这样

1: MinWidth + (int)croppedBitmap.Width - MinWidth - MaxWidth <= croppedBitmap.Width
2: 0 + 1323 <= croppedBitmap.Height
编辑2: 1.您的宽度小于0(在本例中为-1),这不应该是这种情况 2.即使它将>0,也会导致错误,因为877+x是>裁剪位图。宽度,这是不允许的

所以我从一开始就说,你必须确保你的宽度和高度必须大于0,并且你的矩形的宽度+最小宽度和高度+0之和不能超过你图像的边界

现在,您的矩形如下所示:

new Rectangle(877, 0, -1, 1323) // Rectangle(posx, posy, width, height)
正如你所看到的,宽度是负数,这不是你想要的,它必须大于0。如果你现在就这么做:

new Rectangle(877, 0, 1, 1323)
这仍然是错误的,因为你的矩形是从877到878(x坐标),这是不可能的,因为你的图像只有877像素宽。这意味着
MinWidth
(int)crappedbitmap.Width-MinWidth-MaxWidth
是错误的。你必须确保你的价值观不会导致这些问题


这不是复制方法的问题,而是传递参数的问题。你必须在通过之前检查它们

很抱歉,我是新来的。我不太明白,我该怎么办?我已经在
crappedbitmap=crappedbitmap.Clone前面添加了它(
,在解除Bug时出现错误,该错误表示当前上下文中不存在名称“Debug”
,因为您需要使用System.Diagnostics;错误的参数通常会导致System.Drawing出现OOM异常。因此请确保所选矩形有效。@Layne裁剪应用程序本身会成功运行。但是n将它与其他应用程序结合在一起会产生这样的结果。您认为问题是什么?
new Rectangle(877, 0, 1, 1323)