Solved

Get Image Path from Resources

Posted on 2011-09-15
7
1,186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 40
ID: 36543913
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
ID: 36544002
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
ID: 36544375
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 36544502
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
ID: 36544752
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
ID: 36549423
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
ID: 36550379
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

622 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