2011-07-11 170 views
0

異常詳細信息:System.ArgumentException:參數無效。該方法的c#參數無效

Bitmap result = new Bitmap(7016, 9921); 

部分:

public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight) 
{ 
    Bitmap result = new Bitmap(nWidth, nHeight); 

nWidth和nHeight參數有明確的價值觀和仍然相同的錯誤拋出同樣的錯誤,所以我取代它,它似乎對人數較少的工作雖然,但:

http://msdn.microsoft.com/en-us/library/7we6s1x3.aspx

似乎並沒有表明有什麼限制?我試過了:

Bitmap result = new Bitmap(nWidth, nHeight); 
Bitmap result = new Bitmap(7016, 9921); 
Bitmap result = new Bitmap((int)7016, (int)9921); 

所有的失敗都是一樣的。

+4

類似:http://stackoverflow.com/questions/6333681/c-parameter-is-not-valid-creating-new-bitmap – AakashM

+0

由於可用內存而發生異常。 Piotr可能有更多的記憶。 – RvdK

+0

檢查這個http://stackoverflow.com/questions/5801652/bitmap-while-assigning-height-width-crashes/5802113#5802113 ..類似於你現在的 – V4Vendetta

回答

2

我相信沒有足夠的內存來分配位圖。

+0

我需要多少內存?這不會拋出一個不同類型的錯誤? –

+0

〜265.5MB。但請注意,它應該是記憶的連續部分。您也可以將BPP值從32更改爲24或16 - 這將需要更少的內存。 – treetey

0

當您沒有可用內存分配如此大的塊時會發生此錯誤。

不可否認,這不是一個很好的錯誤信息,我不確定爲什麼微軟選擇了這個錯誤信息而不是OutOfMemory異常,但這就是結果。