Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1304
  • Last Modified:

Get Image Path from Resources

Hello EE,

I have inserted into my Projet folder 2 images. I have then added them into Resources under Images.

now in my Code I would like get the string path of it, kind of:   My.Resources.thisPicture1.Path.ToString()

This is not valid but its an example for you.. I dont get how to retrive the path ?
0
PhilippeRenaud
Asked:
PhilippeRenaud
  • 4
  • 3
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
You can't from the code.

When you embed an image, it becomes part of the .exe. The project's files keep a record of the path, but that information is not compiled into the application, so the code does not have access to it.

If you need to be able to access the image file at runtime, do not add it to the resources. Add the image file to your project and flag it as Content it the Build Action property of the file. When preparing your deployment, include the Content files.
0
 
PhilippeRenaudAuthor Commented:
Lets say my png file is with all my forms, inside my solution then.

If I do My.Application.Info.DirectoryPath  it brings me too far (at debug I think)

How do I get the Projet forms level ?
0
 
Jacques Bourgeois (James Burger)Commented:
Let's take it from the start.

What are you doing with the image. Are you only showing it in your forms? Will it have to be modified after the application is distributed?

Why do not need the path? If the image is in the resources, you do not need the file.

If you have difficulty with English, answer in English first for everybody else on the site...

... and give me also you ranswer in French. It might be easier to get the details straight.

-----

... et donne-moi aussi ta réponse en français. Ce serait peut-être plus clair
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
PhilippeRenaudAuthor Commented:
I have a chart inside my form.

with the chart, inside my code, I have this line :

ctFinancial.Legends("Default").CustomItems(1).Cells(0).Image =   ...

.Image needs a String for the image (so the path of it)


I can't use the Resource because it will be an object
So I have place the image .png file located at the same place as my form.
Now I want to say:  

ctFinancial.Legends("Default").CustomItems(1).Cells(0).Image =   "the path of my image located at the same place as my form"

.. :)  I think it's clear? no need in french
0
 
Jacques Bourgeois (James Burger)Commented:
Yes, it's clear.

The easiest way to do that is to place the image file in the application directory or in a subdirectory of the application directory. The application directory is the default directory when an application starts, so you would not have to deal with the path.

While debugging, simply copy it in all the bin directories you have under your project.

Flag the file as Content as suggested in my first comment.

When you prepare your deployment, be sure to include the image file in the installation so that it will be in the same place relative to the application.
0
 
PhilippeRenaudAuthor Commented:
Yes its already flaged as Content.


Alors si je comprends il faudrait que je mettre mes png dans le bin folder ?? Me semble que ca va pas la..?


Ensuite je fais :   My.Application.Info.DirectoryPath & "pict.png"

qqch de meme ?
0
 
Jacques Bourgeois (James Burger)Commented:
That's it. If you need a path, you need a file.

The limitation comes from your chart object. It should be able to accept an Image object, but from what you say it requires a String. Bad design in my opinion. A class should give some latitude to the programmers that use it.

Mixing images with executables is never a good thing however. What I do in my applications is that I often have a Data or Support or Images subdirectory in bin (and in the installation directory when I deploy). I leave bin to the compiler and put everything else in bin\Images

My.Application.Info.DirectoryPath & "\Images\pict.png"

Quelque chose de même.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now