Relative path when creating a bitmap

I am trying to create Bitmapusing:

bitmap = new Bitmap(@"Movies\View\Images\missing_person.bmp"); 

However, I get an error System.ArgumentException.

The file I'm calling from is in:

MyProj\DisplaySideBarCommand.cs          

Images are in:

MyProj\Movies\View\Images\missing_person.bmp

I also tried using:

bitmap = new Bitmap(@"..\Movies\View\Images\missing_person.bmp"); 

but got the same error.

+4
source share
3 answers

It will search for files regarding the execution assembly. When you build a project, it is probably displayed in a directory, for example, bin\debugor bin\release. You could build your relative path to retreat from there, or copy the files to the output directory.

Content , ( ) , .

+2

, ProjectDirectory\bin\Debug\ - @"..\..\Movies\View\Images\missing_person.bmp"

0

, , .

string projectFolder = "..\\..\\"; // Goes back to the project folder

projec, :

bitmap = new Bitmap(projectFolder + @"Movies\View\Images\missing_person.bmp");

, . , ( , .)

0

All Articles