Main Menu

Load Image from an URL

Started by romeroa, April 07, 2017, 03:36:10 PM

Previous topic - Next topic

romeroa

Is it possible to load an image (jpg i.e.) directly from an URL?

Richard Moss

Hello,

It's not something the ImageBox will do naively, but it is easy enough to add yourself. I've updated the demonstration program on GitHub to show how to do this, appropriate code below.

try
{
  using (WebClient client = new WebClient())
  {
    byte[] data;

    data = client.DownloadData(url);

    using (Stream stream = new MemoryStream(data))
    {
      this.OpenImage(Image.FromStream(stream));
    }
  }
}
catch (Exception ex)
{
  MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}


Regards;
Richard Moss
Read "Before You Post" before posting (https://forums.cyotek.com/cyotek-webcopy/before-you-post/). Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

romeroa

Thanks.
Again, you help me. Working fine.