ALX
Well-known member
I apologize for asking such basic questions. There are things that get missed when you learn this stuff from a book without any formal guidance. You folks ARE my formal guidance. So this question has to do with using Dispose to avoid locks on files and memory leaks.
There are a couple questions embedded in the comments in the code above that have puzzled me for a long time and I'm finally getting around to trying to iron these things out in my head.
VB.NET:
bmp = New Bitmap("somegraphicfile.bmp")
bmp1 = New Bitmap(somewidth, someheight)
bmp2 = New Bitmap(somewidth, someheight)
g = Graphics.FromImage(bmp1)
g.DrawImage(bmp, 0, 0, somewidth, someheight) ' Draw bmp to bmp1
bmp.Dispose() ' Release the lock on "somegraphicfile.bmp"
g.Dispose() ' Does this also release the lock on the file ?
g = Graphics.FromImage(bmp2)
g.DrawImage(bmp1, 0, 0, somewidth, someheight) ' Draw bmp1 to bmp2
' Does g need to be Disposed before reassigning g to another Graphics object or
' can I wait until I've completed the tasks and then Dispose g at the end ?
bmp = New Bitmap(somewidth, someheight)
g = Graphics.FromImage(bmp)
g.DrawImage(bmp1, 0, 0, somewidth, someheight) ' Draw bmp1 to bmp
g.Dispose()