Hallo zusammen,
ich habe ein Problem. Ich speichere in einem Programm Bilder, und bevor ich dies tue lege ich ein Overlay auf das Bild. Das speichern selber klappt problemlos, aber wenn ich das Overlay drauflege bekommt mein Programm ein Speicherleck. Meine Overlay Funktion sieht wie folgt aus. Das Leck tritt nur im "True" Fall auf. Dort möchte ich zunächst mein Ursprungsbild, das ich der Funktion übergebe, um einen gewissen Wert vergrößern. Ich versuche eigentlich alle Ressourcen freizugeben, sowohl Bitmaps wie auch die Graphics-Objekte, aber trotzdem staut sich irgendwas im Speicher auf und ich habe keine Idee mehr, woran das liegt.
Function makeoverlay(ByVal bmp As Bitmap) As Bitmap
Dim g As Graphics = Graphics.FromImage(bmp)
Dim theight, theight2 As Integer
theight = g.MeasureString(Date.Now.ToString, New Font("Arial", _
25)).Height
theight2 = g.MeasureString(Date.Now.ToString, New Font("Arial", _
12)).Height
Dim boxloc, timestamploc, commentloc As Point
Select Case CaptureStuff.append
Case True
'---------------- Problem tritt hier auf --------------------
'No Memory leak, if False, so it must be something problematic here
Dim oldheight As Integer = bmp.Height
Dim newbmp As New Bitmap(bmp.Width, bmp.Height + Math.Max(CInt( _
CaptureStuff.height + 6), CInt(3 * theight2)))
Dim imgdraw As Graphics = Graphics.FromImage(newbmp)
imgdraw.FillRectangle(Brushes.White, 0, 0, newbmp.Width, _
newbmp.Height)
imgdraw.DrawImage(bmp, 0, 0)
imgdraw.Dispose()
g.Dispose()
bmp.Dispose()
bmp = newbmp
g = Graphics.FromImage(bmp)
'--------------------------------------------------------
boxloc = New Point(10, oldheight + 2)
timestamploc = New Point(CaptureStuff.width + 20, oldheight + 2)
commentloc = New Point(CaptureStuff.width + 20, oldheight + 2 + _
theight2 + 3)
Case False
timestamploc = New Point(10, 10)
boxloc = New Point(10, 10 + 10 + theight)
commentloc = New Point(10, 10 + 10 + theight + 10 + _
CaptureStuff.height)
End Select
'....
'hier wird noch ein wenig auf g herumgemalt
'....
g.Dispose()
Return bmp
End FunctionIch würde mich sehr freuen, wenn ihr mal drüber schauen könntet. Vieleicht fällt euch der Fehler ins Auge. Falls weitere Infos benötigt sind, immer gern.
Vielen Dank und beste Grüße
Keex |