1

I need to display the images from remote database.here I have a code to display images from local file.But I can't get it from remote server

C# code

DispatcherTimer timer = new DispatcherTimer();
        List<string> files = new List<string>() { "http://technomindtech.com/1tele-pixel.com/ad/banner.jpg", "http://technomindtech.com/1tele-pixel.com/ad/logo_banner.jpg", "http://technomindtech.com/1tele-pixel.com/ad/images.jpeg" };


        List<BitmapImage> images = new List<BitmapImage>();
            int current = 0;

                foreach (string file in files)
                {
                    BitmapImage image = new BitmapImage(new Uri(file, UriKind.Relative));
                    images.Add(image);
                }

                timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(3);
                timer.Tick += new EventHandler(timer_Tick);

                timer.Start();

     void timer_Tick(object sender, EventArgs e)
            {
                Image1.Source = images[current];

                current++;
                if (current >= files.Count)
                    current = 0;
            }

Xaml code

<Image x:Name="Image1"  Stretch="Fill" Width="410" Grid.ColumnSpan="3" Margin="-8,0,-29,0"  />

but it throws Uri exception it can't show the image

4

1 回答 1

1

在您的 foreach 块中,从 Uri 创建图像时,您声明路径是相对的,但实际上是绝对的。因此,修改语句应该有效:

BitmapImage image = new BitmapImage(new Uri(file, UriKind.Absolute));
于 2013-07-15T07:30:22.400 回答