Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 Windows Phone中的幻灯片放映_Windows Phone 7_Windows Phone 7.1 - Fatal编程技术网

Windows phone 7 Windows Phone中的幻灯片放映

Windows phone 7 Windows Phone中的幻灯片放映,windows-phone-7,windows-phone-7.1,Windows Phone 7,Windows Phone 7.1,我有一个URL数组。每个url包含一个图像。我需要一个接一个地下载,然后开始幻灯片放映。我尝试使用循环下载每个文件并显示它们。但每当我试图得到之前的图像,我什么也得不到 我的代码如下所示 string [] urlArray; int currentItem; int totalItems; private void StartSlideShow() { for(int i=0;i < totalItems;i++) { DownloadImage(urlA

我有一个URL数组。每个url包含一个图像。我需要一个接一个地下载,然后开始幻灯片放映。我尝试使用循环下载每个文件并显示它们。但每当我试图得到之前的图像,我什么也得不到

我的代码如下所示

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--;
    }
}
string[]urlArray;
int当前项目;
整数项目;
私有void StartSlideShow()
{
对于(int i=0;i1)
{
下载图像(URLARY[currentItem-1]);
当前项目--;
}
}
然后,我尝试先下载所有图像并保存到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);
    }
}
private void wc\u OpenReadCompleted(对象发送方,OpenReadCompletedEventArgs e)
{
bi.设置源(即结果);
biArr[currentItem].SetSource(即结果);
如果(currentItem==totalItems])
放映幻灯片(biArr);
}
专用void显示幻灯片(BitmapImage[]biArr)
{
对于(int i=0;i
然后我尝试将图像转换为byteArray,并将其保存到名为BMPList的列表中。(列出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);
    }
}
private void wc\u OpenReadCompleted(对象发送方,OpenReadCompletedEventArgs e)
{
BitmapImage bi=新的BitmapImage();
bi.设置源(即结果);
使用(MemoryStream ms=new MemoryStream())
{
WriteableBitmap btmMap=新的WriteableBitmap(bi.PixelWidth,bi.PixelHeight);
System.Windows.Media.Imaging.Extensions.SaveJpeg(btmMap,ms,bi.PixelWidth,bi.PixelHeight,01100);
BMPList.Add(ToArray女士());
}
如果(currentItem==totalItems)
放映幻灯片(BMPList);
}
专用作废幻灯片(列表BMPList)
{
for(int i=0;i

如何下载所有图像并开始幻灯片放映?

您不需要自己下载图像,只需将
图像的
源代码指向Uri即可


有关在处理大量基于web的图像时避免内存问题的详细信息,请参见。

另外,请任何人告诉我如何格式化代码。有关格式化的信息,请参见选择您的代码并使用ctrl+K,此元数据为您提供:谢谢回复。如果只有一个图像正在加载,它将正常工作。但是当我尝试加载多个项目(使用循环)时,什么也没有发生。