Solved

Get Image Path from Resources

Posted on 2011-09-15
7
1,090 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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