C# 如何比较图像(缓存图像)?
我正在metro风格的应用程序中进行简单的图像缓存。以下是我已经做过的:C# 如何比较图像(缓存图像)?,c#,windows-8,microsoft-metro,windows-runtime,C#,Windows 8,Microsoft Metro,Windows Runtime,我正在metro风格的应用程序中进行简单的图像缓存。以下是我已经做过的: private async void GetImage() { bool isFolderExisting = true; bool isFileExisting = true; StorageFolder storageFolder = null; StorageFile storageFile = null; // get
private async void GetImage()
{
bool isFolderExisting = true;
bool isFileExisting = true;
StorageFolder storageFolder = null;
StorageFile storageFile = null;
// get screenshots folder
try
{
storageFolder = await ApplicationData.Current.TemporaryFolder.GetFolderAsync("screenshots");
}
catch (System.IO.FileNotFoundException ex)
{
isFolderExisting = false;
}
// if folder doesn't exist, create new one
if (isFolderExisting == false)
storageFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("screenshots");
// get screenshot
try
{
storageFile = await storageFolder.GetFileAsync(this.LinkId);
//IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync((source) => { updateImage(storageFile); });
}
catch (System.IO.FileNotFoundException ex)
{
isFileExisting = false;
}
// if file doesn't exists, download and save new one
if (isFileExisting == false)
{
var uri = new Uri(WebServiceAddress + "/screenshot/" + this.LinkId, UriKind.Absolute);
var thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(uri);
storageFile = await StorageFile.CreateStreamedFileFromUriAsync(this.LinkId, uri, thumbnail);
await storageFile.CopyAsync(storageFolder, storageFile.Name, NameCollisionOption.ReplaceExisting);
}
//this.ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appdata:///temp/screenshots/" + this.LinkId));
this.Image = "ms-appdata:///temp/screenshots/" + this.LinkId;
}
现在我要处理最后一部分,比较图像。
我正在检查临时文件夹中是否存在图像。如果它不存在,我只是下载新的,但如果存在,我需要检查它是否和服务器上的相同。如何实现这一点?在StorageFile类上使用该方法。该对象包含一个DateModified属性,可用于在客户端和服务器之间进行比较