OutOfMemoryException 未处理
我更改了 使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几个小时前我刚刚遇到了类似的问题,请检查克隆的边界。如果您移到位图之外,它将抛出此异常。
所以要小心这种情况。
如果我的猜测是正确的 1 & 2 未满足
编辑:
将其添加到克隆前面并将结果发布在您的帖子
EDIT2中:
1. 您的宽度< 0(在本例中为-1),但不应出现这种情况
2.即使是> 0 会导致错误,因为 877 + x > > CroppedBitmap.Width 这是不允许的
所以我从一开始就说的是你必须确保你的宽度和高度必须大于 0 并且矩形的宽度 + MinWidth 和高度 + 0 的总和必须是'不要超出图像的边界。
现在你的矩形看起来像这样:
正如你所看到的,宽度是负数,这不是你想要的,它必须大于 0。所以如果你现在这样做:
它仍然是错误的,因为你的矩形将来自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.
if my guess is correct 1 & 2 are not fulfilled
EDIT:
Add this in front of Clone and post the result in your post
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:
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:
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!