vb.net 从 url 设置图像框中的图像而无需下载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14839135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:18:48  来源:igfitidea点击:

set image in image box from a url with out downloading

vb.netimageurl

提问by Ioan Loosley

I am writing a program in vb.net for listening to the radio.

我正在 vb.net 中编写一个程序来收听广播。

How do I make it so I can load a image of the internet with out permanently downloading it to the hard drive. Because if I do this

我如何制作它以便我可以加载互联网图像而无需将其永久下载到硬盘驱动器。因为如果我这样做

PictureBox1.BackgroundImage = "http://www.bbc.co.uk/radio1/chart/assets/a/aviciivsnickyromero/single/icouldbetheonenicktim/artwork/26948.jpg"

but it will say Error 2 Value of type 'String' cannot be converted to 'System.Drawing.Image'.

但它会说“字符串”类型的错误 2 值无法转换为“System.Drawing.Image”。

回答by Sam Axe

Download it to an in-memory stream.

将其下载到内存流。

Dim tClient as WebClient = new WebClient

Dim tImage as Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData(url)))

PictureBox1.Image = tImage