Resource Folder/Publishing Question
I have been using Image.FromFile to display jpegs and other image files. For the first time I'm beginning to publish my program, but I get errors about not finding the pictures I want to see using Image.FromFile.
This may be an obvious question, but I'm just trying to understand the basics of publishing: I should import every resource that I plan on using correct? I can't just use Image.From file and expect it to work when published right?
Thanks
Re: Resource Folder/Publishing Question
All right, so I did some research on embedding resources, which isn't what I want to do in my circumstance. I just need to make sure the pictures are in the exact same file directory on both my development machine and on the user's machine if I use Image.FromFile.
Re: Resource Folder/Publishing Question
The way we do it in our application is that the main app directory has a /bin folder where the .exe - and all the other dll's - are stored. There are other directories in the project as well, and we refer to those directories in our application using the "../" prefix. This tells windows to look up one directory from where the exe resides and then start looking for the file.
So in your case, you would have a directory structure say like this:
c:\program files\your app\bin
c:\program files\your app\images
... maybe some other directories as well.
Then, when referring to a file in the images directory, you would use the path "../images/image1.gif".
OK. So that's when it's installed. How do you make this work in development? Well, by default the compiled .exe or .dll will go to the obj/debug directory, but it doesn't have to be that way. Under project settings, you can tell VS where to put the .exe. So you setup a directory structure on your system that mirrors what will be when installed, and tell your application to put the compiled exe there. That way, when you run the app in the dev environment to test some code, it will put the .exe in the proper place and the .exe will know, via the relative path, where to find the files.
Clear as mud?
Re: Resource Folder/Publishing Question
Why not extract the resource then?
Code:
My.Resources.sss.Save("C:\example.jpeg", Drawing.Imaging.ImageFormat.Jpeg)
Re: Resource Folder/Publishing Question
Quote:
Originally Posted by
dolot
The way we do it in our application is that the main app directory has a /bin folder where the .exe - and all the other dll's - are stored. There are other directories in the project as well, and we refer to those directories in our application using the "../" prefix. This tells windows to look up one directory from where the exe resides and then start looking for the file.
So in your case, you would have a directory structure say like this:
c:\program files\your app\bin
c:\program files\your app\images
... maybe some other directories as well.
Then, when referring to a file in the images directory, you would use the path "../images/image1.gif".
OK. So that's when it's installed. How do you make this work in development? Well, by default the compiled .exe or .dll will go to the obj/debug directory, but it doesn't have to be that way. Under project settings, you can tell VS where to put the .exe. So you setup a directory structure on your system that mirrors what will be when installed, and tell your application to put the compiled exe there. That way, when you run the app in the dev environment to test some code, it will put the .exe in the proper place and the .exe will know, via the relative path, where to find the files.
Clear as mud?
I had to read it a few times, but you do make sense, thanks. It's bit of isn't it?
Thanks!
Re: Resource Folder/Publishing Question
Quote:
Originally Posted by
ident
Why not extract the resource then?
Code:
My.Resources.sss.Save("C:\example.jpeg", Drawing.Imaging.ImageFormat.Jpeg)
I have another app where we compile images in as resources like this. You actually don't have to extract the resources to a file, but can assign it straight to the image.
Code:
Me.ImagePanel.BackgroundImage = My.Resources.ImageResources.PointFrontWall
Re: Resource Folder/Publishing Question
Yeh i am well aware you don't have to extract resources. It was inline with what the OP asked for.
Re: Resource Folder/Publishing Question
Quote:
Originally Posted by
ident
Yeh i am well aware you don't have to extract resources. It was inline with what the OP asked for.
I understand - no offense meant.