OutOfMemoryException 未处理

发布于 2025-01-05 15:31:21 字数 860 浏览 1 评论 0原文

我更改了 使用 Accord.NET 自动图像拼接 我在 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  

I change the Automatic Image Stitching with Accord.NET application to stitch multiple files.
I put a for loop at the btnDoItAll code, the loop will depend on how many images was to stitch.
I have joined a cropping code at the end of the loop. you can see the here.
The an error showed up which said OutOfMemoryException was unhandled - Out of memory in this part.

croppedBitmap = croppedBitmap.Clone(new Rectangle(MinWidth, 0, (int)croppedBitmap.Width - MinWidth - MaxWidth, 1323), System.Drawing.Imaging.PixelFormat.DontCare);

hope you can help me again.

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  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑咖 2025-01-12 15:31:21

几个小时前我刚刚遇到了类似的问题,请检查克隆的边界。如果您移到位图之外,它将抛出此异常。

所以要小心这种情况。

1: MinWidth + (int)croppedBitmap.Width - MinWidth - MaxWidth <= croppedBitmap.Width
2: 0 + 1323 <= croppedBitmap.Height

如果我的猜测是正确的 1 & 2 未满足

编辑:
将其添加到克隆前面并将结果发布在您的帖子

Debug.WriteLine("Bitmap-width: "+croppedBitmap.Width);
Debug.WriteLine("Bitmap-height: "+croppedBitmap.Height);
Debug.WriteLine("Width: "+(croppedBitmap.Width - MinWidth - MaxWidth));
Debug.WriteLine("MinWidth: "+MinWidth);

EDIT2中:
1. 您的宽度< 0(在本例中为-1),但不应出现这种情况
2.即使是> 0 会导致错误,因为 877 + x > > CroppedBitmap.Width 这是不允许的

所以我从一开始就说的是你必须确保你的宽度和高度必须大于 0 并且矩形的宽度 + MinWidth 和高度 + 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)croppedBitmap.Width - MinWidth - MaxWidth 是错误的。你必须确保你的价值观不会导致此类问题。

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

I just had a similar problem a few hours ago check your boundaries for Clone. If you move outside of your bitmap it will throw this exception.

So be careful that this is the case.

1: MinWidth + (int)croppedBitmap.Width - MinWidth - MaxWidth <= croppedBitmap.Width
2: 0 + 1323 <= croppedBitmap.Height

if my guess is correct 1 & 2 are not fulfilled

EDIT:
Add this in front of Clone and post the result in your post

Debug.WriteLine("Bitmap-width: "+croppedBitmap.Width);
Debug.WriteLine("Bitmap-height: "+croppedBitmap.Height);
Debug.WriteLine("Width: "+(croppedBitmap.Width - MinWidth - MaxWidth));
Debug.WriteLine("MinWidth: "+MinWidth);

EDIT2:
1. Your width is < 0 (in this case -1) which shouldn't be the case
2. Even if it would be > 0 it would result in an error since 877 + x is > croppedBitmap.Width which is not allowed

So what I was saying from the very beginning is that you have to make sure that your width and height have to be larger 0 AND that the sum of width + MinWidth and height + 0 from your rectangle mustn't exceed the boundaries of your image.

Right now your rectangle looks like this:

new Rectangle(877, 0, -1, 1323) // Rectangle(posx, posy, width, height)

So as you can see the width is negative which is not what you want it has to be larger 0. So if you would do this now:

new Rectangle(877, 0, 1, 1323)

It would still be wrong since your rectangle would be from from 877 to 878 (x coordinate) which can't be since your image is only 877 pixels wide. This means MinWidth and (int)croppedBitmap.Width - MinWidth - MaxWidth are wrong. You have to make sure that your values don't cause these kind of problems.

It's not a problem with the Copy method it's more a problem of the passed parameters. You have to check them before passing them!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文