I have the following code to resize an image to a certain size:
Public Sub ResizeBitmap(ByRef uSource As Bitmap, ByVal uSize As Size)
Dim nBmp As New Bitmap(uSize.Width, uSize.Height)
Using g As Graphics = Graphics.FromImage(nBmp)
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g.DrawImage(uSource, New Rectangle(0, 0, uSize.Width, uSize.Height))
End Using
uSource = nBmp
End Sub
I'm experiencing an Unknown GDI+ exception if I call this frequently, but not an out of memory exception. Since GDI+ is not always clear in it's errors, I'm suspecting a memory leak anyways as TaskManager shows a rising amount of RAM being used.
I would therefore like to ask if the above code contains any flaws and if yes, how to get rid of them.
I think I'm quite ok at memory management, but bitmaps really bring me to my limits sometimes.
Thank you.