简体   繁体   中英

Load image from URL to pictureBox

I'm trying to load several images from URLs to a pictureBox. My problem is that "pictureBox.Load(URL)" or "pictureBox.ImageLocation = URL" doesn't work. I don't know why, I think it is because the URL doesn't have an extension like .jpg.

private void button3_Click(object sender, EventArgs e)
{
    string URL = "https://internetmarke.deutschepost.de/internetmarke/franking/image/view/1403556118.do";
    pictureBox1.ImageLocation = URL;
}

The URL works in Firefox and the picture is shown. But in IE it doesn't work and I think that's the same reason why it's not working in .NET.

IE says "unknown filetype" and wants to download a "1403556118.do" file.

In C# I only get a red X in the pictureBox.

When I first try to load it in IE, it works in the pictureBox (IE cache?)

Does somebody knows another possibility to load this images to a pictureBox?

EDITED: Added sample code.


Today I've tested the code on three different computers and with different Internet connections; Home DSL, Company DSL and a UMTS/3G Surf-Stick. All without any proxies and also tested without virusscan.

In every single scenario it didn't work, same as I wrote in my first post.

After I accessed some of the URLs in Firefox or IE, the images of these URLs showed up in my application. All others remained a red X.

Is there any different (old-school^^) method to load these images, like downloading the HTTP-Stream into a byte array and then copy this into pictureBox.Image or something?

Dino

pictureBox1.ImageLocation = "http://www.micoequipment.com/products/large/MF_260_l.jpg"; //should work

Make sure that image is accessible via web browser (test it before). Also, please make sure that you are calling correct picture box :) It works for me.

@Andrew:

pictureBox1.ImageLocation = "http://www.micoequipment.com/products/large/MF_260_l.jpg";

This Works!

pictureBox1.ImageLocation = "https://internetmarke.deutschepost.de/internetmarke/franking/image/view/1403556118.do";

This doesn't work!

Your link and my link both work in Firefox. But my link doesn't work in IE and it doesn't work in .NET and in the pictureBox.

这应该可以工作,因为您是从远程 URL 加载图像:

pictureBox1.Load(URL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM