'Show an image from a URL in WinForms PictureBox
Hi I have a WinForms project targetting .net core. I am trying to load an image from a URL, but all I am getting is this:
Inside a UserControl I have added a PictureBox (pic1) and a Button.
Added the following as an example to the click event of the button:
pic1.LoadAsync("https://images.pexels.com/photos/4815143/pexels-photo-4815143.jpeg");
also
pic1.ImageLocation = "https://images.pexels.com/photos/4815143/pexels-photo-4815143.jpeg";
Have tried with different URLs
Any ideas what is wrong?
Edit I've tried an alternative option, something seems to be getting stuck on DownloadData
using (WebClient webClient = new WebClient())
{
byte[] data = webClient.DownloadData("https://images.pexels.com/photos/4815143/pexels-photo-4815143.jpg");
using (MemoryStream mem = new MemoryStream(data))
{
using (var yourImage = Image.FromStream(mem))
{
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

