将图像从 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
Load Image from My.Resources to a Picturebox (VB.NET)
提问by Moondoggie
I'm having trouble loading an image from My.Resources. I have already tried a no. of codes like....:
我在从 My.Resources 加载图像时遇到问题。我已经试过了。代码如....:
PictureBox1.Image = My.Resources.Online_lime_icon;
AndPictureBox1.Image = CType(My.Resources.ResourceManager.GetObject("Online_lime_icon"), Image)
PictureBox1.Image = My.Resources.Online_lime_icon;
和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 String
resource and I think it represents fileName
with 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)