C #: access to image added to project folder

I would like to know the following: I added the Graphics folder to my project and stuck BMP in it. Now I would like to load an image from my code, but I cannot figure out how to do this. I know this is just with resources, but is there a way without adding an image to the resources? Thanks

+6
c # visual-studio image embedded-resource
source share
4 answers

I also thought about this, so I realized this and posted it in a message. For your example, it should be something like this:

var a = Assembly.GetExecutingAssembly(); // Or another Get method if you need to get it from some other assembly var image = Image .FromStream(a.GetManifestResourceStream("DefaultNameSpace.Graphics.image.bmp")); 

Do not forget to mark the image as a built-in resource and get rid of the image when it is done so that you do not get a leak :)

+2
source share

You can download the image directly from the file system.

Image img = Image .FromFile ("\ Graphics \ ImageName.bmp");

MSDN documentation is here

http://msdn.microsoft.com/en-us/library/system.drawing.image.fromfile.aspx

Obviously, you need to know the directory and name that you are loading.

+3
source share

To get a resource:

 myNamespace.Properties.Resources.images.<imagename> 

You can apply this to the type you need (or use a function like FromFile, for example)

+1
source share

You must specify the file properties that should be deployed when creating the application:

Copy to output directory: always copy

Then you can access the file using the Image.FromFile method, the path will be the same as in your project.

0
source share

All Articles