我有一個網址陣列。每個網址都包含一個圖片。我需要逐一下載並開始幻燈片播放。我試圖用循環下載每個文件並顯示它們。但是每當我試圖獲得前一張圖片時,我什麼也得不到。在Windows Phone上幻燈片顯示
我的代碼如下所示
string [] urlArray;
int currentItem;
int totalItems;
private void StartSlideShow()
{
for(int i=0;i < totalItems;i++)
{
DownloadImage(urlArray[i]);
}
}
private void DownloadImage(string url)
{
WebClient wc=new WebClient();
wc.OpenReadCompleted+=new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri(url));
}
private void wc_OpenReadCompleted(object sender,OpenReadCompletedEventArgs e)
{
BitmapImage bi=new BitmapImage();
bi.SetSource(e.Result);
imgThumbnail.Source=bi;
}
private void btnNext_Click(object sender, RoutedEventArgs e)
{
if (currentItem < totalItems)
{
DownloadImage(urlArray[currentItem+1]);
currentItem++;
}
}
private void btnBack_Click(object sender, RoutedEventArgs e)
{
if (currentItem > 1)
{
DownloadImage(urlArray[currentItem-1]);
currentItem--;
}
}
然後我被試圖先下載所有的圖像,並保存到BitmapImage的陣列,並試圖完成下載之後,開始幻燈片放映。這種情況下沒有顯示任何內容。
的代碼是
private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
bi.SetSource(e.Result);
biArr[currentItem].SetSource(e.Result);
if(currentItem==totalItems])
ShowSlides(biArr);
}
private void ShowSlides(BitmapImage[] biArr)
{
for(int i=0;i < totalItems;i++)
{
imgThumbnail.Source=biArr[i];
System.Threading.Thread.Sleep(5000);
}
}
然後我試圖將圖像轉換爲字節組,並將其保存到一個列表中的名稱BMPList。 (List BMPList)。完成後,我想只顯示一個黑色的顏色顯示爲圖像的圖像下載後
的代碼是
private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(e.Result);
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap btmMap = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);
System.Windows.Media.Imaging.Extensions.SaveJpeg(btmMap, ms, bi.PixelWidth, bi.PixelHeight, 0, 100);
BMPList.Add(ms.ToArray());
}
if(currentItem == totalItems)
ShowSlides(BMPList);
}
private void ShowSlides(List<byte[]> BMPList)
{
for(int i=0; i < BMPList.Count;i++)
{
if (BMPList[currentDisplayItem] != null)
{
MemoryStream ms = new MemoryStream(BMPList[i], 0, BMPList[i].Length);
ms.Write(BMPList[i], 0, BMPList[i].Length);
BitmapImage img = new BitmapImage();
img.SetSource(ms);
imgThumbnail.Source = img;
}
System.Threading.Thread.Sleep(5000);
}
}
我如何可以下載所有圖像,並開始播放幻燈片?
也請任何人告訴我如何格式化代碼。 – 2012-03-08 11:05:17
有關格式化的信息,請參閱http://stackoverflow.com/editing-help – 2012-03-08 11:12:02
選擇您的代碼,並給ctrl + K,這個元爲你:http://meta.stackexchange.com/questions/22186/how-do-我的格式我的代碼塊 – 2012-03-08 11:13:33