[英]How can I compare images (caching images)?
我正在都市風格的應用程序中進行簡單的圖像緩存。 這是我已經完成的工作:
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類上使用GetBasicPropertiesAsync方法。 BasicProperties對象包含一個DateModified屬性,可用於在客戶端和服務器之間進行比較。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.