Codecat
Codecat

Reputation: 2241

PictureBox.Load method loading images from the internet slow at first request

I have posted a question about a similar issue before, and managed to fix that by setting the "Proxy" property of the object to null. However, with PictureBox.Load(String) this is a different issue. As far as I know, there's no Proxy property for that.

And so, the first call of picPreview.Load(URL); takes a while.

Is anyone aware of a method to set the Proxy application-wide, or for a PictureBox?

Thanks.

PS: picPreview.ImageLocation = URL; does the same as picPreview.Load(URL);.

Upvotes: 1

Views: 2116

Answers (1)

Codecat
Codecat

Reputation: 2241

I fixed this by downloading the image into a MemoryStream first.

        WebClient wc = new WebClient();
        wc.Proxy = null;
        byte[] bFile = wc.DownloadData(URL);
        MemoryStream ms = new MemoryStream(bFile);
        Image img = Image.FromStream(ms);
        picPreview.Image = img;

Upvotes: 4

Related Questions