将图像从 My.Resources 加载到 Picturebox (VB.NET)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12065568/
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-09 16:15:23  来源:igfitidea点击:

Load Image from My.Resources to a Picturebox (VB.NET)

vb.netpictureboxmy.resources

提问by Moondoggie

I'm having trouble loading an image from My.Resources. I have already tried a no. of codes like....:

我在从 My.Resources 加载图像时遇到问题。我已经试过了。代码如....:

  1. PictureBox1.Image = My.Resources.Online_lime_icon;And

  2. PictureBox1.Image = CType(My.Resources.ResourceManager.GetObject("Online_lime_icon"), Image)

  1. PictureBox1.Image = My.Resources.Online_lime_icon;

  2. PictureBox1.Image = CType(My.Resources.ResourceManager.GetObject("Online_lime_icon"), Image)

but it would still return:

但它仍然会返回:

Picturebox1.Image = Nothing

回答by adatapost

Try to convert it ToBitMap()

尝试转换它 ToBitMap()

 PictureBox1.Image = My.Resources.Online_lime_icon.ToBitmap()

EDIT:

编辑:

@user1615710 : My.Resources.Online_lime_icon doesn't have .ToBitmap. It only has .ToString.

@user1615710:My.Resources.Online_lime_icon 没有 .ToBitmap。它只有 .ToString。

That means you've Stringresource and I think it represents fileNamewith or without absolute path.

这意味着你有String资源,我认为它代表fileName有或没有绝对路径。

Try to print/show the content of My.Resources.Online_lime_icon

尝试打印/显示的内容 My.Resources.Online_lime_icon

 Debug.Print(My.Resources.Online_lime_icon) 'or
 MsgBox(My.Resources.Online_lime_icon)

If it is realpath then load the image via,

如果它是真实路径,则通过以下方式加载图像,

 PictureBox1.Image = Image.FromFile(My.Resources.Online_lime_icon)