Here is the code (thought it might help)
Dim asr As AppSettingsReader = New AppSettingsReader
Dim sRemoteDirectory As String = CType(asr.GetValue("RemoteDirectory",
GetType(String)), String)
Dim sBackupDirectory As String = CType(asr.GetValue("BackupDirectory",
GetType(String)), String)
Dim img As Image = Image.FromFile(path)
Dim imgFormat As Imaging.ImageFormat = GetImageFormat(path)
'Maintain aspect ratio
Dim scale As Double = 0
Dim width, height As Integer
width = CType(asr.GetValue("ImageWidth", GetType(String)), Integer)
height = CType(asr.GetValue("ImageHeight", GetType(String)), Integer)
'Caters for the user specifying 0 for either width or height
If width = 0 Then
width = 1
ElseIf height = 0 Then
height = 1
End If
If img.Height < img.Width Then
scale = width / img.Width
Else
scale = height / img.Height
End If
Dim newwidth As Integer = CInt(scale * img.Width)
Dim newheight As Integer = CInt(scale * img.Height)
Dim bmp As New Bitmap(img, newwidth, newheight)
img.Dispose()
'Add a log entry
SaveToLog(filename)
Dim sRemotePath As String = String.Format("{0}\{1}", sRemoteDirectory,
filename)
bmp.Save(sRemotePath, imgFormat)
bmp.Dispose()
Dim sBackupPath As String = String.Format("{0}\{1}", sBackupDirectory,
filename)
File.Copy(path, sBackupPath, True)
File.Delete(path)
"Rocky" <da***********@hotmail.com> wrote in message
news:eH**************@TK2MSFTNGP04.phx.gbl...
Hi Greg,
Yes, the image is being disposed each time. I will look into the other
things you
mentioned.
"Greg Young" <dr*******************@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP03.phx.gbl... Are you rememberring to dispose the Image?
Also have your profiled your app? Depending what you are doing you may be
creating many large objects (which get collected differently). What is
the memory usage of your app if watched through performance monitor?
btw: a 2000x2000 image does use a good deal of memory
Cheers,
Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
"Rocky" <da***********@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...I have a vb.net service which copies images and resizes images from a
local
directory to a remote one.
When I drop images into the local directory I get an out of memory error
after several images - the exception is on the following line.
Dim img As Image = Image.FromFile(path)
The machine has a GB of ram, and there is not a great deal running.
Each image is about 2000 x 2000 PIXELS
Thanks for any help in advance