whosyodaddy Posted October 9, 2003 Posted October 9, 2003 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 Quote
whosyodaddy Posted October 10, 2003 Author Posted October 10, 2003 Hmm... Does anybody not know or are they too lazy?:confused: Quote
*Experts* Volte Posted October 10, 2003 *Experts* Posted October 10, 2003 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". Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 I get a Debug Error: Value of 'System.IO.Stream' cannot be converted to 'System.Drawing.Image'. Quote
*Experts* Volte Posted October 11, 2003 *Experts* Posted October 11, 2003 Oops, sorry, that should be:img = Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("YourNamespace.YourFileName")) Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 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! Quote
*Experts* Volte Posted October 11, 2003 *Experts* Posted October 11, 2003 Have you remembered to set the Build Action of the image to Embedded Resource? Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 Have you remembered to set the Build Action of the image to Embedded Resource? Yes. Same Problem. Quote
*Experts* Volte Posted October 11, 2003 *Experts* Posted October 11, 2003 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 = imgWorks for me, and my project is called VBTestApp. Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 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? Quote
kymarty Posted October 11, 2003 Posted October 11, 2003 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. Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 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. Quote
kymarty Posted October 11, 2003 Posted October 11, 2003 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. Quote
kymarty Posted October 11, 2003 Posted October 11, 2003 I wonder if the spaces in your project name are making a difference. My project name is 3 words long but no spaces between the words. Quote
Leaders dynamic_sysop Posted October 11, 2003 Leaders Posted October 11, 2003 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 Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 (edited) Ill post my project .....hopefully somebody will run through it and see...age of mythology the titans.zip Edited March 24, 2006 by PlausiblyDamp Quote
kymarty Posted October 11, 2003 Posted October 11, 2003 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. Quote
kymarty Posted October 11, 2003 Posted October 11, 2003 Either way. Thanks for the tips. It solved a huge problem for me. :) Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 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 Quote
*Experts* Volte Posted October 11, 2003 *Experts* Posted October 11, 2003 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. Quote
whosyodaddy Posted October 11, 2003 Author Posted October 11, 2003 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: ;) Quote
Mohsen Posted October 15, 2003 Posted October 15, 2003 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 ;) Quote
Administrators PlausiblyDamp Posted October 15, 2003 Administrators Posted October 15, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted November 20, 2003 Posted November 20, 2003 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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.