我正在嘗試重新上傳圖片大小。從我在網上找到的內容來看,實現這一點的方法是創建一個您想要的大小的新圖像,然後使用圖形將圖像繪製爲較小的圖像。似乎適用於上傳的所有圖像,但尼康D90相機的圖像除外。每當我嘗試上傳並重新設置這些圖像的大小時,我都會在下面顯示的行中看到OutOfMemoryException。任何人都可以告訴我我做錯了什麼。DrawImage導致OutOfMemoryException
'Create the new image as a blank bitmap
Dim resized As Image = New Bitmap(newWidth, newHeight)
'Create a new graphics object from the new image
Dim g As Graphics = Graphics.FromImage(resized)
'Resize graphics object to fit onto the resized image
g.DrawImage(originalImage, New Rectangle(0, 0, resized.Width, resized.Height)) <-- Exception
g.Dispose()
我正在使用FromFile。我得到了與FromStream相同的錯誤,但我猜測原因是一樣的。圖像將在Paint.Net中打開,如果我在Paint.Net中重新調整大小,然後上傳它們,它們就可以正常工作。這對我的最終用戶來說似乎是一個不必要的步驟。 BinaryReader解決方案涉及什麼? – BLeB 2009-07-29 17:27:24