我必須在由相機捕獲的圖像上畫一些東西。這適用於許多設備,但有時RAM太小或圖片太大,並且該功能會因OutOfMemory異常而崩潰。新位圖上的OutofMemory異常()
我怎麼能: 一)優化代碼,以防止這種異常 二)處理這個異常(從而使照片更小,可用RAM等
這裏是代碼:
Dim from_bmp As Bitmap
Dim bmp As Bitmap
from_bmp = New Bitmap(picname)
'I also tryed this with a function which is creating the Bitmap from Filestream
'I also tryed this with the OpenNETCF.Drawing.Imaging.IImage
'If the Original Pictiure is too big, the function will crash here.
bmp = New Bitmap(from_bmp.Width, from_bmp.Height + stampheight)
'now I Create a bitmap which is higher than the original, in order to write the stamp beneth the picture
Dim font As New System.Drawing.Font("Arial", 30, FontStyle.Regular)
gr = Graphics.FromImage(bmp)
gr.DrawImage(from_bmp, 0, 0)
from_bmp.Dispose()
'here I draw somethin in the Bitmap
bmp.Save(deststring, System.Drawing.Imaging.ImageFormat.Jpeg)
gr.Dispose()
bmp.Dispose()
升級系統內存是最好的選擇 – Predator 2011-05-26 15:08:39
@Gens這種異常通常出現在很多平臺上,不僅僅是Windows,而不僅僅是.NET。 – 2011-05-26 15:13:53
這是net.cf,代碼在移動設備上運行,我無法升級它們的Memorya^^ – 2red13 2011-05-26 15:14:21