Solved

Get Image Path from Resources

Posted on 2011-09-15
7
950 Views
Last Modified: 2012-08-13
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
Comment
Question by:PhilippeRenaud
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
 
LVL 1

Author Comment

by:PhilippeRenaud
Comment Utility
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
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:PhilippeRenaud
Comment Utility
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:PhilippeRenaud
Comment Utility
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
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now