to monitoe files in a specifc directory, if images are added to the
directory they are resized and saved in a remote directory. The original
file is then backed up and deleted from the image directory.
The code is as follows
Friend Shared Sub ResizeImage(ByV al path As String, ByVal filename As
String)
Dim asr As AppSettingsRead er = New AppSettingsRead er
Dim sRemoteDirector y As String = CType(asr.GetVa lue("RemoteDire ctory",
GetType(String) ), String)
Dim sBackupDirector y As String = CType(asr.GetVa lue("BackupDire ctory",
GetType(String) ), String)
' Dim img As Image = ImageFromFile(p ath)
(This was put in as an alternative but produced the same problem
//
Dim fs As FileStream = New FileStream(file name, FileMode.Open,
FileAccess.Read )
Return Image.FromStrea m(fs)
fs.Dispose()
//
Dim img As Image = Image.FromFile( path) << It fails here
Dim imgFormat As Imaging.ImageFo rmat = GetImageFormat( path)
'Maintain aspect ratio
Dim scale As Double = 0
Dim width, height As Integer
width = CType(asr.GetVa lue("ImageWidth ", GetType(String) ), Integer)
height = CType(asr.GetVa lue("ImageHeigh t", 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(filen ame)
Dim sRemotePath As String = String.Format(" {0}\{1}", sRemoteDirector y,
filename)
bmp.Save(sRemot ePath, imgFormat)
bmp.Dispose()
' Dim sBackupPath As String = String.Format(" {0}\{1}", sBackupDirector y,
filename)
' File.Copy(path, sBackupPath, True)
' File.Delete(pat h)
Whether I copy a couple of images or lots, the error is always the same
The call stack is as follows
[External Code]
GeminiPictureSe rvice.exe!Gemin iPictureService .GeneralRoutine s.ResizeImage(s tring
path = "C:\\Pictur e Test 1\\IMGP0353.JPG ", string filename =
"IMGP0353.J PG") Line 18 + 0x9 bytes Unknown
GeminiPictureSe rvice.exe!Gemin iPictureService .GeminiPictureS ervice.fswGemin i_Created(objec t
sender = {System.IO.File SystemWatcher}, System.IO.FileS ystemEventArgs e =
{System.IO.File SystemEventArgs }) Line 42 + 0x20 bytes Unknown
[External Code]
Exception
- $exception {System.OutOfMe moryException: Out of memory.
at System.Drawing. Image.FromFile( String filename, Boolean
useEmbeddedColo rManagement)
at System.Drawing. Image.FromFile( String filename)
at GeminiPictureSe rvice.GeneralRo utines.ResizeIm age(String path, String
filename)
at GeminiPictureSe rvice.GeminiPic tureService.fsw Gemini_Created( Object
sender, FileSystemEvent Args e)
at System.IO.FileS ystemWatcher.On Created(FileSys temEventArgs e)
at System.IO.FileS ystemWatcher.No tifyFileSystemE ventArgs(Int32 action,
String name)
at System.IO.FileS ystemWatcher.Co mpletionStatusC hanged(UInt32 errorCode,
UInt32 numBytes, NativeOverlappe d* overlappedPoint er)
at
System.Threadin g._IOCompletion Callback.Perfor mIOCompletionCa llback(UInt32
errorCode, UInt32 numBytes, NativeOverlappe d* pOVERLAP)} System.Exceptio n
{System.OutOfMe moryException}
Memory - I checked the process and the memory usage spiked from 8,000 to
(40-46k), it stayed at around 40k before giving an exception
System Pentium 1.8GHz 1GB Ram Windows XP Pro SP2
Thanks for any help in advance