【问题标题】:Load Image from My.Resources to a Picturebox (VB.NET)将图像从 My.Resources 加载到 Picturebox (VB.NET)
【发布时间】:2012-08-17 10:20:05
【问题描述】:

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

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

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

但它仍然会返回:

Picturebox1.Image = Nothing

【问题讨论】:

    标签: vb.net picturebox my.resources


    【解决方案1】:

    尝试转换ToBitMap()

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

    编辑:

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

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

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

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

    如果是真实路径,则通过加载图片,

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

    【讨论】:

    • 感谢您的回答,但My.Resources.Online_lime_icon 没有.ToBitmap。它只有.ToString
    • 是文件路径还是流?
    • @AVD 我使用消息框检查了 .ToString 的全部内容,结果它只是说明了对象的类型:它的输出是“System.Drawing.Bitmap”@Cole Johnson这是我导入到资源中的位图。
    • 这对我有用:ImageBox1.BackgroundImage = My.Resources.my_image。我的图像框是 UI.ImageBox 类型的。
    猜你喜欢
    • 2011-05-03
    • 2016-05-18
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多