Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How do you make the picture box display a image that you imported in your project? I know this is how you do It for a certain image on your computer:

 

If ComboBox1.SelectedItem = "Pig Sticker" Then

PictureBox1.Image = System.Drawing.Image.FromFile("c:\folder\image.jpg")

 

What do i put so that there is code PictureBox1.Image= And then there is the code for showing the image that is imported in your project. Thanks:D

  • *Experts*
Posted
You need to set the image's Build Action property to 'Embedded Resource', and then use:
Dim img As Image

img = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("YourNamespace.YourFileName")

If the base namespace is called "WordProc" and the file is called "toolbar.bmp", the resource stream name would be "WordProc.toolbar.bmp".

  • *Experts*
Posted
Oops, sorry, that should be:
img = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("YourNamespace.YourFileName"))

Posted

Thanks, although whenever I click 'Pig Sticker' In the ComboBox, i get a debug error like so:

 

An unhandled exception of type 'System.ArguementException' occured in system.drawing.ddl

 

Additional Information: 'null' is not a valid value for 'stream'.

 

The program runs and debugs, but whenever I click on that I get that error.

 

Here is my code:

 

   Dim IMG As Image
       If NorseTechno.SelectedItem = "Pig Sticker" Then
           PictureBox1.Image = IMG
           IMG = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ballista.ballista.jpg"))
       End If

 

Thanks... please help!

  • *Experts*
Posted

And ballista is the name of your base namespace (usually the same as your project name)?

 

        Dim img As Image = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("VBTestApp.av.jpg"))
       Me.BackgroundImage = img

Works for me, and my project is called VBTestApp.

Posted

Hmm... I guess I was confused with the 'namespace' thing. I thought it was when you click on the picture, you type in the Namespace you want in 'Custom Tool Namespace'. So I typed that in the code.

What Is the Namespace thing? I tried my Project Name and Form, still same error! Thanks for the replies, and for your help. Does anybody know why?

Posted
I've been playing around with the same code and realized that the namespace and the filename are case sensitive. I got the same error as above when i typed it in all lower case but when I used mixed case, as my project is named, everything worked just fine. You might double check your case.
Posted
I've been playing around with the same code and realized that the namespace and the filename are case sensitive. I got the same error as above when i typed it in all lower case but when I used mixed case, as my project is named, everything worked just fine. You might double check your case.

 

My case was Perfectly fine. Same error.:o

My Project is named "Age of Mythology The Titans" and I put ("Age of Mythology The Titans.ballista.jpg"). Can somebody be a pal and send me a example file? With the same name? Thanks.

Posted
Not sure why yours doesn't work then. The only difference in my code is that my file is a bitmap and i use "DIM bmpCard1 as Bitmap" instead of using IMAGE. I got the same error you typed above until I corrected the case in my statement and now it displays correct with no errors.
  • Leaders
Posted
Dim IMG As Image

If NorseTechno.SelectedItem = "Pig Sticker" Then

PictureBox1.Image = IMG

IMG = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ballista.ballista.jpg"))

End If

at this point ..... Dim IMG As Image , the image is null because you havent set it yet ( ie: IMG = blabla ) , you need the PictureBox1.Image = IMG line to be after the line .... IMG = Image.FromStream .... eg:

Dim IMG As Image
       If NorseTechno.SelectedItem = "Pig Sticker" Then
           '/// moved this line... PictureBox1.Image = IMG down.
           IMG = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ballista.ballista.jpg"))
           '/// and put it here....
           PictureBox1.Image = IMG '/// IMG shouldnt be null here.
       End If

Posted
I had my 2 lines swapped backwards at first also but didn't get the error. I also didn't get the picture either until I swapped the 2 lines of code and assigned the picture to the variable and then assigned the control to = the variable.
Posted
at this point ..... Dim IMG As Image , the image is null because you havent set it yet ( ie: IMG = blabla ) , you need the PictureBox1.Image = IMG line to be after the line .... IMG = Image.FromStream .... eg:

Dim IMG As Image
       If NorseTechno.SelectedItem = "Pig Sticker" Then
           '/// moved this line... PictureBox1.Image = IMG down.
           IMG = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ballista.ballista.jpg"))
           '/// and put it here....
           PictureBox1.Image = IMG '/// IMG shouldnt be null here.
       End If

 

I already tried that a while ago... but I'll try again.

 

Tried Again... same error. Same Problem. Plz help, look at my project posted above. Thanks. I appreciate all of your time and effort to help me:D Gee whiz... I feel like a geek:p

  • *Experts*
Posted
whosyodaddy: right click on your project name in the Solution Explorer, and click the Properties item that pops up, and use the text that's in the "Root Namespace" textbox as your namespace. If your project has multiple words, the namespace probably has _ separated words or something, since namespaces can't have spaces.
Posted

Thanks so much volteface! It worked! You have no Idea how much you help out; me and this community. You are a god *bows down*. It turns out that the spaces DID effect it as we thought.

 

I had this:

Age of Mythology The Titans

 

It needed this:

 

Age_of_Mythology_The_Titans

 

Thanks again everybody!:rolleyes:

:D

:cool:

;)

Posted

This would have saved your problem,

pbOk.Image = Image.FromFile(Application.StartupPath & "uploadingok2.gif")

 

and you place the image "uploadingok2.gif" in the "bin" folder of your project

 

Why didn't u try that guys? Keep me updated,

Moshen ;)

  • Administrators
Posted
One reason is that it would require the application to ship with several image files - if a user deleted any then the app would fail. Using an embedded resource means there is no need for all the separate files to be managed / installed / updated.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 1 month later...
Posted

Volte -

 

Thanks... searched MSDN for an hour trying to find that... something that should be so simple... burried so deep in the Relection namespace... thanks again!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...