将图像从 url 加载到 PictureBox 中
我想将图像加载到 PictureBox
中。这是我要加载的图像:http://www.gravatar。 com/avatar/6810d91caff032b202c50701dd3af745?d=identicon&r=PG
我该怎么做?
I want to load an image into a PictureBox
. This is the image I want to load: http://www.gravatar.com/avatar/6810d91caff032b202c50701dd3af745?d=identicon&r=PG
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
PictureBox.Load(string url) 方法“设置ImageLocation 到指定的 URL 并显示指定的图像。"
The PictureBox.Load(string url) method "sets the ImageLocation to the specified URL and displays the image indicated."
试试这个:
Try this:
这是我使用的解决方案。我不记得为什么我不能只使用 PictureBox.Load 方法。我很确定这是因为我想正确缩放和扩展将下载的图像置于 PictureBox 控件的中心。如果我记得的话,PictureBox 上的所有缩放选项要么拉伸图像,要么调整 PictureBox 的大小以适合图像。我想要一个正确缩放且居中的图像,其大小与我为 PictureBox 设置的大小相同。
现在,我只需要制作一个异步版本...
这是我的方法:
这是所需的包含内容。 (其他代码可能需要一些,但为了安全起见,包括所有内容)
我通常如何使用它:
Here's the solution I use. I can't remember why I couldn't just use the PictureBox.Load methods. I'm pretty sure it's because I wanted to properly scale & center the downloaded image into the PictureBox control. If I recall, all the scaling options on PictureBox either stretch the image, or will resize the PictureBox to fit the image. I wanted a properly scaled and centered image in the size I set for PictureBox.
Now, I just need to make a async version...
Here's my methods:
Here's the required includes. (Some might be needed by other code, but including all to be safe)
How I generally use it:
如果您尝试在 form_load 中加载图像,那么最好使用代码,
不仅从 Web 加载,而且在表单加载中也不会出现延迟。
If you are trying to load the image at your form_load, it's a better idea to use the code
not only loading from web but also no lag in your form loading.