In this code i'm getting the last image file i have 5723 image:
i = last_image_file();
Next_File = sf + @"\radar" + i.ToString("D6") + ".png";
pictureBox1.Load(Next_File);
In this case the last file is: radar005723.png Now the problem is that the file was donloaded not correctly either by internet connection problem but in this case i think the problem that my pc stuck frozen and i restarted the pc over so the download wasnt completed or the file got damaged.
How can i add to my code something that will check the image file before this one and if it is good file to show it in the pictureBox1 ? And the file before the last one is damaged too so check the one before and so untill he find the most last working/good file.
And then to delete all the damaged images.
EDIT**
I have changed the code to this:
I have already a method in my project that test for bad files so i did:
i = last_image_file();
Next_File = sf + @"\radar" + i.ToString("D6") + ".png";
bad_file = Bad_File_Testing(Next_File);
if (bad_file == true)
{
File.Delete(Next_File);
}
else
{
pictureBox1.Load(Next_File);
}
But bad_file is not true so its keep going to the pictureBox1.Load(Next_File); and keep throwing the exception: Parameter is not valid I also tried to load the file with the program Paint and it couldnt load the file so i know the file is bad but why the method: Bad_File_testing didn't return true ?
This is the Bad_File_Testing method:
private bool Bad_File_Testing(string file_test)
{
try
{
Image radar = Bitmap.FromFile(bad_file_test_dir + testing_file);
radar.Dispose();
return true;
}
catch
{
Logger.Write("Last radar image was damaged and have been deleted");
return false;
}
}
The exception:
System.ArgumentException was unhandled
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Windows.Forms.PictureBox.Load()
at System.Windows.Forms.PictureBox.Load(String url)
at mws.Form1.show_latest_downloaded_image() in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\Form1.cs:line 1862
at mws.Form1..ctor() in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\Form1.cs:line 467
at mws.Program.Main() in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\Program.cs:line 25
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
This is how im using Georgi method:
i = last_image_file();
Next_File = sf + @"\radar" + i.ToString("D6") + ".png";
bool bad_file = IsValidGDIPlusImage(Next_File);
if (bad_file == true)
{
File.Delete(Next_File);
}
else
{
pictureBox1.Load(Next_File);
}