2012-02-12 194 views
0

我改變Automatic Image Stitching with Accord.NET應用縫合多個文件。
我把for loop放在btnDoItAll的代碼上,循環將取決於要縫合多少圖像。
我在循環結尾加入了裁剪代碼。你可以看到here
在這部分中出現的錯誤顯示爲OutOfMemoryException was unhandled - Out of memoryOutOfMemoryException異常是未處理

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 
+0

可能的重複[是否有原因Image.FromFile拋出一個無效的圖像格式OutOfMemoryException?](http://stackoverflow.com/questions/2610416/is-there-a-reason-image-fromfile-throws -out-outofmemoryexception-for-an-invalid-i) – BrokenGlass 2012-02-12 18:41:25

回答

1

我剛剛在幾個小時前有一個類似的問題檢查克隆的邊界。如果你移動到位圖之外,它會拋出這個異常。

所以要小心這種情況。

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哪個是正OT允許

那麼,我從一開始說的是,你必須確保你的寬度和高度都較大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是錯誤的。你必須確保你的價值觀不會導致這些問題。

這不是與複製方法的問題,它更傳遞參數的問題。你必須在通過它們之前檢查它們!

+0

對不起,我是這個東西的新手。我不太明白,我應該怎麼做? – 2012-02-12 18:48:29

+0

我在前面加上它'croppedBitmap = croppedBitmap.Clone(',有上debbuging其中甾體抗炎藥'名稱「調試」因爲你需要使用System.Diagnostics程序不會在當前context' – 2012-02-12 19:14:35

+0

存在的錯誤; – 2012-02-12 19:15:44