Jump to content

Mudar image source em runtime

Recommended Posts



tenho uma imagem e quero mudar em runtime a source.

O problema é que a imagem que eu pretendo está na web e não estou a conseguir fazê-lo.

Alguém pode ajudar?


Share this post

Link to post
Share on other sites

Encontrei este tópico:


string urlGetImage = http://yoururlgoeshere.com/a.jpg;

WebClient wc = new WebClient();
System.IO.Stream stream = wc.OpenRead(urlGetImage);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream);
bmp.Save(currentImageDirectory + aerialImageFileName);
loadImageFromFile(currentImageDirectory + aerialImageFileName);

private void loadImageFromFile(string filename)
            // Avoid locks on file.
            byte[] byteArray = File.ReadAllBytes(currentImageDirectory + aerialImageFileName);
            MemoryStream memoryStream = new MemoryStream(byteArray, 0, byteArray.Length, false, false);
            byteArray = null;

            BitmapImage currentBitmapImage = new BitmapImage();
            currentBitmapImage.StreamSource = memoryStream;
            imgMain.Source = currentBitmapImage;
            currentBitmapImage = null;

vê se te ajuda.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.