Hi.
I want to open an Image. But, I don't know how to do it in a relativ way :
I have a directory with pictures : Picture.
It is located in my work directory.
So, how can I open the image ?
For the moment, I have that, and it does not work :
Image newImage = Image.FromFile("../Picture/Computer.jpg");
I have tried this also :
Image newImage = Image.FromFile("Picture/Computer.jpg");
But, same result : it does not find the file.
Any idea ? 14 21263
Hi Mathieu,
If you are using Visual Studio .Net remember that the code directory is not the same as the startup directory. So, if your work directory is the same as the code directory you need to do Image.FromFile("../../Picture/Computer.jpg");
... means go to parent directory, which causes you to be inside "bin", so go back one more to get to your work directory.
Happy coding!
Morten Wennevik [C# MVP]
"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news:opr748tzlzklbvpo@morten_x.edunord... Hi Mathieu,
If you are using Visual Studio .Net remember that the code directory is
not the same as the startup directory. So, if your work directory is the
same as the code directory you need to do
Image.FromFile("../../Picture/Computer.jpg"); .. means go to parent directory, which causes you to be inside "bin", so
go back one more to get to your work directory.
With the Application.StartupPath, I have noticed that I am in :
\bin\debug
But, the problem is that when I will do a release, will it be ok like this ?
(in the release, I won't be in \debug, nop ?)
"Mathieu Chavoutier" <no****@no.spam> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl... "Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de news:opr748tzlzklbvpo@morten_x.edunord... Hi Mathieu,
If you are using Visual Studio .Net remember that the code directory is not the same as the startup directory. So, if your work directory is the same as the code directory you need to do Image.FromFile("../../Picture/Computer.jpg"); .. means go to parent directory, which causes you to be inside "bin", so
go back one more to get to your work directory.
With the Application.StartupPath, I have noticed that I am in : \bin\debug
But, the problem is that when I will do a release, will it be ok like this ? (in the release, I won't be in \debug, nop ?)
No, it will break in the release version. I would either use conditional
compilation(one of the few times I would) to define the string differently
based on the build version or have the build perform a post-build step and
copy the files to a particular runtime folder.
I would put the Picture directory in the debug directory. Then you could use
Image.FromFile("Picture/Computer.jpg");
or to be on the safe side
Image.FromFile(Application.StartupPath + "/Picture/Computer.jpg");
Otherwise, you should probably use the UserAppDataPath property and put the Picture directory there, or make a registry entry specifying where the Picture directory is located.
Happy coding!
Morten Wennevik [C# MVP]
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> a écrit dans le
message de news:OG**************@TK2MSFTNGP09.phx.gbl... No, it will break in the release version. I would either use conditional compilation(one of the few times I would) to define the string differently based on the build version or have the build perform a post-build step and copy the files to a particular runtime folder.
Isn't it possible to find the main directory ?
When I work in
c:\blabla\
The compiler knows where to find code sources. So, why is it so difficult to
find the same directory ?
"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news:opr7493ny0klbvpo@morten_x.edunord... I would put the Picture directory in the debug directory. Then you could
use Image.FromFile("Picture/Computer.jpg");
But it is boring to move it every time I will have to do something.
or to be on the safe side
Image.FromFile(Application.StartupPath + "/Picture/Computer.jpg");
That doesn't work, because Application.StartupPath is already in Debug :o/
I wanted to do so :o)
Otherwise, you should probably use the UserAppDataPath property and put
the Picture directory there,
1.0.1598.24545 is the name of the directory.
Hum :o/
or make a registry entry specifying where the Picture directory is
located.
Ouch. I though something easy to do :o)
Seriously, there is no way to find the main directory ?
The main directory of your program is Application.StartupPath. In your case it is something\bin\debug because that is where your program is located when you compile in debug mode. If you switch to release mode, you will find that the directory changes to something\bin\release. Wherever your program is located, Application.StartupPath will report which directory it is.
Happy coding!
Morten Wennevik [C# MVP]
"Mathieu Chavoutier" <no****@no.spam> wrote in message
news:uN****************@TK2MSFTNGP10.phx.gbl... "Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de news:opr7493ny0klbvpo@morten_x.edunord... I would put the Picture directory in the debug directory. Then you could use Image.FromFile("Picture/Computer.jpg");
But it is boring to move it every time I will have to do something.
or to be on the safe side
Image.FromFile(Application.StartupPath + "/Picture/Computer.jpg");
That doesn't work, because Application.StartupPath is already in Debug :o/ I wanted to do so :o)
Otherwise, you should probably use the UserAppDataPath property and put the Picture directory there,
1.0.1598.24545 is the name of the directory.
Hum :o/
or make a registry entry specifying where the Picture directory is located.
Ouch. I though something easy to do :o)
Seriously, there is no way to find the main directory ?
What would be the "main directory"? Generally its whatever directory the app
runs from. Its a pain with debugging, but thats how it is. If you are using
VS2003, you might want to look in to pre and post build events and see if
you can automate moving your files to the bin/debug/Pictures/ directory.
"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news:opr75atpzgklbvpo@morten_x.edunord... The main directory of your program is Application.StartupPath. In your
case it is something\bin\debug because that is where your program is located
when you compile in debug mode. If you switch to release mode, you will
find that the directory changes to something\bin\release. Wherever your
program is located, Application.StartupPath will report which directory it
is.
But it is not normal to change it.
My main directory is blabla, not blabla\bin\Debug, then blabla\bin\Release,
and later blabla.
Why can't I get easily blabla from the beginning ?
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> a écrit dans le
message de news:Og*************@tk2msftngp13.phx.gbl... What would be the "main directory"? Generally its whatever directory the
app runs from.
I think that if VS is moving my objects files, I don't have to know it, and
it doesn't have to modify my way of programming.
Its a pain with debugging, but thats how it is. If you are using VS2003, you might want to look in to pre and post build events and see if you can automate moving your files to the bin/debug/Pictures/ directory.
I will look for it, thanks.
Mathieu Chavoutier <no****@no.spam> wrote: But it is not normal to change it. My main directory is blabla, not blabla\bin\Debug, then blabla\bin\Release, and later blabla.
Why can't I get easily blabla from the beginning ?
Have you tried setting the Working Directory of the project?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de
news:MP************************@msnews.microsoft.c om... Mathieu Chavoutier <no****@no.spam> wrote: But it is not normal to change it. My main directory is blabla, not blabla\bin\Debug, then
blabla\bin\Release, and later blabla.
Why can't I get easily blabla from the beginning ?
Have you tried setting the Working Directory of the project?
Do you mean programmatically or with the VS tools ?
If you speak about doing it with the program, it is not possible [for me to
find my directory programmatically]
But, if you speak about an VS tools, I am interested, :o)
I don't understand how does it works.
Mathieu Chavoutier <no****@no.spam> wrote: Have you tried setting the Working Directory of the project?
Do you mean programmatically or with the VS tools ?
If you speak about doing it with the program, it is not possible [for me to find my directory programmatically] But, if you speak about an VS tools, I am interested, :o) I don't understand how does it works.
I mean manually, from VS.NET. Right click on the project, select
Properties, then go to Configuration Properties / Advanced. There's a
property there called Working Directory.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de
news:MP************************@msnews.microsoft.c om... Mathieu Chavoutier <no****@no.spam> wrote: Have you tried setting the Working Directory of the project?
Do you mean programmatically or with the VS tools ?
If you speak about doing it with the program, it is not possible [for me
to find my directory programmatically] But, if you speak about an VS tools, I am interested, :o) I don't understand how does it works.
I mean manually, from VS.NET. Right click on the project, select Properties, then go to Configuration Properties / Advanced. There's a property there called Working Directory.
For me it was in Debug, but I finally found, thank you. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pnp |
last post by:
Why does Image.FromFile() fails (OutOfMemoryException) when I try to load an
icon file from the filesystem, that contains 32bit and 24bit icons, but
works fine for Icon files with only 32bit icons...
|
by: anastasia |
last post by:
I get an out of memory exception when attempting to excecute the
following code:
original = System.Drawing.Image.FromFile(file.FileName,true);
I ONLY get this exception when the file is in the...
|
by: bsmalik |
last post by:
Hi All,
I am trying to do a simple thing.
-----------------------------
Dim NCImage As System.Drawing.Image = System.Drawing.Image.FromFile("NC.jpg")
----------------------------
I have the...
|
by: steve |
last post by:
imports system.drawing
imports system.drawing.image
dim img as image = image.fromfile("a.bmp")
picturebox1.image = img
i'm using vs 2003 and the error i have is that fromfile is not a member...
|
by: Taiwo |
last post by:
When I use the method "System.Drawing.Image.FromFile(pictureFile)" where
pictureFile is the path to a valid image file, the file is locked even
minutes after the statement executes. This code is in...
|
by: escristian |
last post by:
Hello.
I'm trying to create an Image so I use something like this:
Image newImage = Image.FromFile(filename);
Now when it's a bmp file and certain .gif files it gives me an
exception that...
|
by: =?Utf-8?B?WVhR?= |
last post by:
Hello,
I used Image.FromFile method to get lots of images from files, it's very
slow in Windows Vista, but it's fast in Windows XP! could anyone please tell
how to speed in Windows Vista? thank you
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |