-
Jul 4th, 2014, 11:10 AM
#1
Thread Starter
Hyperactive Member
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
Intermediate Level Programmer Extraordinaire
-
Jul 4th, 2014, 02:52 PM
#2
Thread Starter
Hyperactive Member
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.
Intermediate Level Programmer Extraordinaire
-
Jul 4th, 2014, 03:15 PM
#3
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?
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jul 4th, 2014, 03:28 PM
#4
Re: Resource Folder/Publishing Question
Why not extract the resource then?
Code:
My.Resources.sss.Save("C:\example.jpeg", Drawing.Imaging.ImageFormat.Jpeg)
Last edited by ident; Jul 4th, 2014 at 03:32 PM.
-
Jul 4th, 2014, 03:53 PM
#5
Thread Starter
Hyperactive Member
Re: Resource Folder/Publishing Question
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!
Intermediate Level Programmer Extraordinaire
-
Jul 4th, 2014, 04:32 PM
#6
Re: Resource Folder/Publishing Question
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
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jul 4th, 2014, 08:42 PM
#7
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.
-
Jul 5th, 2014, 01:06 PM
#8
Re: Resource Folder/Publishing Question
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.
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|