Can anyone tell me what is wrong with the below code i am having no joy figuring this out. I am disposing and have in a using block but keep getting this exception
An unhandled exception of type '
System.OutOfMemoryException
' occurred inSystem.Drawing.dll
Additional information: Out of memory.
foreach (FileInfo file in files)
{
Regex re = new Regex("original", RegexOptions.IgnoreCase);
if (re.IsMatch(file.FullName)) continue;
using (System.Drawing.Image img = System.Drawing.Image.FromFile(file.FullName))
{
if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
filesJpeg.Add(file);
img.Dispose();
}
else
{
img.Dispose();
File.Delete(file.FullName);
}
img.Dispose();
}
}