I have a VB.net (4.5.2) application that I want to use to resize a large number of JPg's from 2048 to 512 width in a batch type mode. I collect the file names in a list box and then index thru the list and resize each file and save it on the disk.
This process works really well for first 800 files then it crashes with an out of memory fault.
Here is a copy of the resize function.
AM I missing something in the cleanup?
My system has 32gb Ram and the PageFile drive has 1Tb with 90% percent available.
I did notice in the resource monitor that the page fault hums along nicely until it gets to the point when the application crashes, the it spikes to 100% and drops off.
Thanks
Nor
Public Function Resize_pix(ByRef InFileNAme As String, maxWidth As Integer, ByRef OutFileName As String) As Boolean
Resize_pix = True
Using newImage As Image = Image.FromFile(InFileNAme)
Aspect = newImage.Height / newImage.Width
Dim newWidth As Integer = maxWidth
Dim newHeight As Integer = maxWidth * Aspect
Using bmp As New Bitmap(newWidth, newHeight)
Using g As Graphics = Graphics.FromImage(bmp)
Try
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, newWidth, newHeight)
g.DrawImage(newImage, 0, 0, newWidth, newHeight)
Catch ex As Exception
g.Dispose()
bmp.Dispose()
newImage.Dispose()
MsgBox("Resize [g.] : " & ex.Message)
Resize_pix = False
End Try
End Using
Try
If Resize_pix Then
bmp.Save(OutFileName.ToString, System.Drawing.Imaging.ImageFormat.Jpeg)
bmp.Dispose()
End If
Catch ex As Exception
bmp.Dispose()
newImage.Dispose()
MsgBox("Resize [save] : " & ex.Message)
Resize_pix = False
End Try
End Using
newImage.Dispose()
End Using
What I have tried:
I dispose of each object in the resize process when I'm done with it. However it seems that some memory is not released.