0
我正在開發一個應用程序,我從網上下載圖像並將它們存儲到獨立存儲中。這是我的代碼。從網下載多張圖片
private void LoadImage(List<ProductImageList> item)
{
BitmapImage bi = new BitmapImage();
foreach (var product in item)
{
string a = product.ImageUrl;
string b = a.Substring(1, a.Length - 2);
Uri uri = new Uri(b, UriKind.RelativeOrAbsolute);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
//load image from Isolated Storage if it already exist
name = System.IO.Path.GetFileName(b);
if (myIsolatedStorage.FileExists(name))
{
}
else
{
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(DownloadCompleted);
wc.OpenReadAsync(uri, wc);
}
}
}
}
private void DownloadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(name);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.Result);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
}
catch (Exception ex)
{
//Exception handle appropriately for your app
}
}
該項目包含圖像標識,ImageUrl.The代碼只下載我的列表的最後圖像的所有time.Please建議我我如何可以下載所有的圖片..