question

SSB-7585 avatar image
0 Votes"
SSB-7585 asked SSB-7585 commented

Can't show Images from URL or download data in WinForms app (Visual Studio)

Hi,
I have a new WinForms project:

  • Visual Studio 2019 16.11.13

  • .NET 5

  • Windows 10

I want to load an image from a URL. When I run the app, nothing shows up. I've tried the following:

pic1.LoadAsync(url);
pic1.ImageLocation = url;

Both of these just result in a placeholder image coming back.


I've also tried downloading the stream - but it is getting stuck

using (WebClient webClient = new WebClient())

 {
 byte[] data = webClient.DownloadData(url);


    using (MemoryStream mem = new MemoryStream(data))
    {
        using (var yourImage = Image.FromStream(mem))
        {
        
        }
    }
 }


Any ideas how to solve for this?

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered SSB-7585 commented

What is the URL ?

If I test with one of my test images, in the constructor, with a PictureBox pictureBox1:

         public Form1()
         {
             InitializeComponent();
             pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
             pictureBox1.ImageLocation = "https://i.ibb.co/DG7XSsB/Butterfly.png";
         }

I get the image :

201019-picture-imagelocation.jpg



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Seems to be that URL. the one you have posted works so i'll take a look at the source server. thanks.

0 Votes 0 ·