Lanc1988 Posted November 30, 2003 Posted November 30, 2003 I have images in my program, so if i just copy the .exe compiled program I made and move it to another computer, it wont open because the image is missing. I am looking for a code that will know the directory where the file is, because I plan to zip all the needed files and once they are unzipped to any location on someone's computer I want the program to know the directory to it. So is there a code that can do this? Or is there a code that will let the program open and just not display the images if they aren't found? Quote
Leaders dynamic_sysop Posted November 30, 2003 Leaders Posted November 30, 2003 why not embed the images ( on your vs menu , click project , add an existing item , choose the images , then when they are listed in your project , set them as " Embedded Resource files " ) then you wont need to search for the images. Quote
aewarnick Posted November 30, 2003 Posted November 30, 2003 If you are going to do that though, make sure you use a compressed image format because they will be embedded exactly as they are with the same size and bytes. Then you can get the images like this: Stream s= System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceStream(name); if(s==null) return null; return (Bitmap)Bitmap.FromStream(s); name is the namespace of your project followed by a dot, then the exact name of the file including the extention. Mine would be AW.embeddedImage.png Quote C#
Lanc1988 Posted November 30, 2003 Author Posted November 30, 2003 Ok thx, I like the embedded idea. I will try it now and see how well it works. Quote
Lanc1988 Posted November 30, 2003 Author Posted November 30, 2003 aewarnick.. im not sure where to put: Stream s= System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceStream(name); if(s==null) return null; return (Bitmap)Bitmap.FromStream(s); Does it go in the code for the PictureBox? Also im not sure about the namespace of my project? Would that be the name of it, whats its saved as?:confused: Quote
Lanc1988 Posted December 1, 2003 Author Posted December 1, 2003 I have changed them to 'embedded resource' but now i dont know where to put the code to display them. Quote
aewarnick Posted December 1, 2003 Posted December 1, 2003 That was actually part of a whole method sub or function. All you need is Stream s= System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceStream(name); Bitmap b= (Bitmap)Bitmap.FromStream(s); Quote C#
Lanc1988 Posted December 1, 2003 Author Posted December 1, 2003 What parts of that need changed? And to what? Quote
Lanc1988 Posted December 1, 2003 Author Posted December 1, 2003 My embedded file is: Treasure.jpg Quote
aewarnick Posted December 1, 2003 Posted December 1, 2003 Stream s= System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceStream("YourNamespace.Treasure.jpg"); Bitmap b= (Bitmap)Bitmap.FromStream(s); Also, Stream is located in the System.IO namespace. Quote C#
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.