Я должен нарисовать что-то на изображении, которое захватывается камерой.Это работает на многих устройствах, но иногда ОЗУ слишком мало или изображения слишком велики, и функция аварийно завершает работу с исключением OutOfMemory.
Как я могу: а) оптимизировать код для предотвращения этих исключений б)Обработайте эти исключения (уменьшите размер изображения, уменьшите объем памяти и т. Д.
, вот код:
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()