2

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

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

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

but it would still return:

Picturebox1.Image = Nothing
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
Moondoggie
  • 61
  • 1
  • 2
  • 9

1 Answers1

8

Try to convert it ToBitMap()

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

EDIT:

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

That means you've String resource and I think it represents fileName with or without absolute path.

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

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

If it is real path then load the image via,

 PictureBox1.Image = Image.FromFile(My.Resources.Online_lime_icon)
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • Thanks for your answer but `My.Resources.Online_lime_icon` doesn't have `.ToBitmap`. It only has `.ToString`. – Moondoggie Aug 22 '12 at 03:46
  • Is it a file path or a stream? – Cole Tobin Aug 22 '12 at 05:43
  • @AVD I used messagebox to check what was the `.ToString` was all about and it turns out it just says the type of the object: it's output was "System.Drawing.Bitmap" @Cole Johnson It's a bitmap I imported to the resources. – Moondoggie Aug 23 '12 at 01:23
  • This worked for me: `ImageBox1.BackgroundImage = My.Resources.my_image` . My image box was of type UI.ImageBox. – awyr_agored Jan 14 '20 at 12:07