0

If I want to add pictures, I have to put those into the resources and access them from the picturebox.Image property by using this:

AddPicturesFromOtherFolders.Properties.Resources.myPicture

Thats the only way I know. That works fine if I have 10 or so images, but what if I had 500 images? Nobody could keep track of anything. So I would like to structure these hyperthetical 500 Images in a folder structure which I could then access with something like:

pictureBox1.Image= ../../Assets/img/specialImages/myImage.png

That would be very neat, but I have found no way, that involves 100% C# code. I would be wuite grateful, if you could help me.

Have a nice day,

Alexander Lenssen

Alexander
  • 33
  • 5

2 Answers2

0

There is no way that involves 100% C# code. At least some Compiler options or Setup actions are nessesary. But the first question is even where to store it: Programm Directory or UserProfiles?

Asuming these images are static (will only change when a installer runs), you can just store them into the Programm Directory. And from there deploy them with the rest of the code. Getting them Into the Output directory is not that difficulty. Visual Studio has options for that: https://msdn.microsoft.com/en-us/library/0c6xyb66.aspx You could go further, like having a Shared Repository for Images (i.e., most Photoshop programms have one Content Folder under Programms).

You can go as far as "soft linking" them, wich means you can have one actuall folder on your disk that will be copied/synched into the output directories on any buil.

If you need to Update those Images them on the fly (without adminsitrative rights), stuff becomes more complicated. You can still do it via the SpecialFolders. CommonApplicationData seems like the right place to put this kind of stuff. Even Steam and Minecraft's old Java Launcher do quite some storage there. Not to mention every WebBrowser.

Christopher
  • 9,634
  • 2
  • 17
  • 31
0

You could use Image.FromFile and load the image from any file you have stored in your file system. For example:

pictureBox1.Image.FromFile(@"D:/Assets/img/specialImages/myImage.png");
Emilio Lucas Ceroleni
  • 1,559
  • 2
  • 9
  • 13