C# 如何比较上次下载的卫星图像和当前下载的卫星图像是否相同?
今天,我想用这节课做一个比较:C# 如何比较上次下载的卫星图像和当前下载的卫星图像是否相同?,c#,.net,winforms,C#,.net,Winforms,今天,我想用这节课做一个比较: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using mws; usin
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using mws;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using DannyGeneral;
namespace General_utility
{
static class File_Utility
{
static public bool File_Comparison(string Filename_1, string Filename_2)
{
FileInfo fi;
int i;
byte[] a,b;
a=File.ReadAllBytes(Filename_1);
b=File.ReadAllBytes(Filename_2);
fi = new FileInfo(a.ToString());
if (a.Length != b.Length)
{
return false;
}
else
{
for (i = 0; i < a.Length; i++)
{
if (a[i] != b[i])
return false;
}
}
return true;
}
}
}
文件比较是一个难题
temp\u sat\u dir是当前下载的文件:C:\Users\temp\satellite.jpg
temp_sat_dir中的文件将始终使用相同的名称
最后一个文件卫星是最后一个下载的文件,我复制到了一个新的目录:C:\Users\satellitiemages\SatImage000863.gif
然后我决定是否下载下一个需要的文件。如果第一个当前文件不相同,则继续并下载其余文件,但如果相同,则不下载其余文件:
if (file_compare == true)
{
break;
}
else
{
try
{
client1.DownloadFile(link, filePath);
}
catch (Exception e)
{
DannyGeneral.Logger.Write(e.ToString());
}
}
第一次文件\u compare为false,它使用client1下载了该文件。
我所有的代码都在循环中,我没有在这里显示,但它在循环中,每15分钟下载9个新文件
但问题是,如果我再次运行该程序,或者如果15分钟过去了,它将继续下载相同的9幅图像
我需要设法让它下载,只有当第一个文件是不一样的最后一个
问题是,文件\u compare现在再次为false。首先它下载了9个文件,现在我再次运行程序,但仍然是错误的。图像和我检查的一样。satellite.jpg和SatImage000863.gif文件是相同的,因此应该进行中断;
但是它没有给出错误。当您将文件复制到“C:\Users\satelliteImages\SatImage000863.gif”时,您显然保存了它而不是复制。即使将其另存为.jpg文件,也可能与原始文件不同。使用system.io.file.copy(或move)来复制原始文件,以便与下载的下一个文件进行比较,而不是进行图像保存。对不起,如果我说的是显而易见的,那么
satellite.jpg
和SatImage000863.gif
怎么可能是相同的呢?它们甚至不是相同的编码格式。请询问您正确的编码格式。但从逻辑上讲,如果我在15分钟后反复下载satellite.jpg文件,但没有任何更改satellite.jpg看起来与我硬盘SatImage000863.gif上的最后一个文件相同,那么它们是相同的。我会改变格式这是我的错误出于某种原因我把卫星作为jpg而不是gif.clais一般来说我不想每次都下载相同的文件,只下载新的。这是一个链接,例如卫星图像的样子:这是一个需要数百万研究经费和五年研究才能找到解决方案的问题。想都别想。
if (file_compare == true)
{
break;
}
else
{
try
{
client1.DownloadFile(link, filePath);
}
catch (Exception e)
{
DannyGeneral.Logger.Write(e.ToString());
}
}