将图像从URL加载到pictureBox

时间:2023-01-24 16:34:44

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.

我正在尝试将多个图像从URL加载到pictureBox。我的问题是“pictureBox.Load(URL)”或“pictureBox.ImageLocation = URL”不起作用。我不知道为什么,我认为这是因为URL没有像.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.

该URL可在Firefox中运行,并显示图片。但是在IE中它不起作用,我认为这与它在.NET中不起作用的原因相同。

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

IE说“未知文件类型”,并想下载“1403556118.do”文件。

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

在C#中我只在pictureBox中得到一个红色的X.

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

当我第一次尝试在IE中加载它时,它适用于pictureBox(IE缓存?)

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

有人知道将这些图像加载到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.

今天我在三台不同的计算机和不同的Internet连接上测试了代码;家庭DSL,公司DSL和UMTS / 3G Surf-Stick。所有没有任何代理,并且没有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.

在我访问Firefox或IE中的某些URL后,这些URL的图像显示在我的应用程序中。所有其他人都是红色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?

是否有任何不同的(老派^^)方法来加载这些图像,比如将HTTP-Stream下载到字节数组中,然后将其复制到pictureBox.Image或其他什么?

Dino

迪诺

2 个解决方案

#1


2  

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.

确保可以通过Web浏览器访问该图像(之前进行测试)。此外,请确保您正在调用正确的图片框:)它适合我。

#2


0  

@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.

您的链接和我的链接都可以在Firefox中使用。但我的链接在IE中不起作用,它在.NET和PictureBox中不起作用。

#1


2  

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.

确保可以通过Web浏览器访问该图像(之前进行测试)。此外,请确保您正在调用正确的图片框:)它适合我。

#2


0  

@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.

您的链接和我的链接都可以在Firefox中使用。但我的链接在IE中不起作用,它在.NET和PictureBox中不起作用。