I have the code below which works great. However I need to loop through images in a folder to convert them. In the same process after the below routene has run I use the tiff file in some document processing. Then I need to delete the tiff file automatically. Problem is it cannot delete the last file used as it throws "File in use by another process" exeption. How can I make sure that the tiff file is no longer used in the code below after the line bm.Save() ?
private Boolean Load_Image(string SourcePath)
{
try
{
DateTime i = DateTime.Now;
label1.Text = "Opening Image....";
Application.DoEvents();
System.Drawing.Image bm = System.Drawing.Image.FromF
ile(Source
Path);
label1.Text = "Converting Image....";
Application.DoEvents();
bm.Save(SourcePath.Replace
(".", "") + "_output.Tiff", System.Drawing.Imaging.Ima
geFormat.T
iff);
bm.Dispose();
bm = null;
DateTime o = DateTime.Now;
TimeSpan u = o - i;
label1.Text = "Conversion Complete." + u.ToString();
Application.DoEvents();
return true;
}
catch(Exception e)
{
label1.Text = "Input File Not ready!" + e.Message ;
return false;
}
}
Start Free Trial