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

1 Answer 1

1

In your foreach block, when creating an image from the Uri, you are stating that the path is relative, but it is actually absolute. So, modifying the statement should work:

BitmapImage image = new BitmapImage(new Uri(file, UriKind.Absolute));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.