How do I store the path to the resource?

The program I am creating is rather difficult to explain as it is intended for very specific personal use, so I will use an example to make it easy to understand:

I have a named class in my project Person

that stores the person's image and name. All images are stored in project resources.

How do I store the path / name of the resource so that I can reuse it in the main program (not in the class Person

)?

For example, if I create a new object Person

in the main program:

Person p = new Person("Michael", Project.Properties.Resources.image);

      

How can I save a variable of what type the path in the class Person

?

public Person(string name, ??? image)

      

Please note that I will need to reuse this image later,

eg:

this.imageBox.Image = p.image;

      

I tried to use objects Image

and Bitmap

, but it just changed imageBox

to empty (I think it sets imageBox.Image

to null

. Also, I'm pretty sure using Bitmap

will copy the image data and use more memory for no reason)

I also tried to use Image.FromFile

and insert the path as a string, but it didn't work.

+3


source to share


1 answer


You don't have to mess with paths if you want to use resources. They are built into the assembly and can be reused from there.

The easiest way to access it - use a class generated resources Project.Properties.Resources.Picture

. The type of the variable will be Image

.



public Person(string name, Image picture)

      

If you want, you can access the resource by manually fetching it from the assembly , but this is similar to this case as far as I can tell.

+3


source







All Articles