Cannot open image

Hello again!

I have done all examples from chapter 12 (Programming -- Principles and Practice Using C++) with success. But now that I've tried to open an image just like it is in the book I can't.
Where was supposed to be the image is a small text "cannot open "image.jpg"". I don't understand what's going on. somebody help me please? (The file "image.jpg" is in the project folder and has 400*212 pixels).

The images are very important for my future work.

Image ii(Point(100,50), "image.jpg");

Thank you!
Perhaps it's simply a problem of an incorrect path. The project folder I presume is where all the source files (.cpp) are located. But where is the executable program itself? Sometimes it may be inside a folder named "release" or "debug" depending on how your system is configured.
I put the images in the folder Debug as you said but still appear the same "cannot open "image.jpg"".
But is there a sub-folder inside "Debug" - and did you identify the actual executable program itself. If that is not useful, you might try specifying a full path to the image, instead of just "image.jpg", something of the style of "C:\\project1\\image.jpg" - as appropriate, and making sure to put a double '\\' to represent each single '\'.
I already put in several folders and write the path but still appear in the same in the window
You might want to just check to see what the current working directory is when you start your program... the IDE can start it anywhere it likes.
@Chervil: All operating systems I know of, including Windows, accept forward slashes in paths. Windows prefers backslashes, but you can mix forward- and back-slashes however you like in paths. To write the most portable code I would prefer use of forward slashes always, especially since you have to escape backslashes.
+1 Duoas

@ OP: On Windows this is done with the "GetCurrentDirectory()" function found here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364934(v=vs.85).aspx

Feeding argc[0] into std::cout seems easier to some people but that actually gives you the path to your executable which isn't necessarily the same as your current working directory.
I am using Microsoft Visual Studio 2010.
In that case make sure this is included somewhere at the top of your code:
 
#include <windows.h> 


Then somewhere in your main function add:
1
2
3
TCHAR MyDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, MyDir);
std::cout << "\nMY CURRENT WORKING DIRECTORY IS: "<< MyDir << std::endl;

This will spit what folder your program is currently working in out to the console display.
Last edited on
If I type this:

#include "C:\Users\pc\Documents\Visual Studio 2010\std_lib_facilities.h" // standard library facilities
#include "C:\Users\pc\Documents\Visual Studio 2010\Projects\TesteFinalSolution\Window.h"


int main ()
{
TCHAR MyDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, MyDir);
std::cout << "\nMY CURRENT WORKING DIRECTORY IS: "<< MyDir << std::endl;
keep_window_open("e");
keep_window_open("e");
}


It doesn't recognize TCHAR MyDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, MyDir);
I didn't prefix all of that to the include command did I? Just write it in as I have it, without a literal path and with brackets instead of the quotes, and your IDE should know where to find that file.
If I didn't prefix all of that to the include command it can't open the files.h
The Windows SDK version of "Windows.h" contains exactly one match for the work "files" and it is not to include a header file. There is no header file named "files.h" in either the Windows 7 SDK or the WinDDK. So where is this error coming from?

Please copy and paste ALL of your code into your next post along with the error you are getting because you're doing something very odd here.
Last edited on
OK. this is my code:

#include "C:\Users\pc\Documents\Visual Studio 2010\Projects\TesteFinalSolution\Simple_window.h"
#include "C:\Users\pc\Documents\Visual Studio 2010\Projects\TesteFinalSolution\Graph.h"
#include "C:\Users\pc\Documents\Visual Studio 2010\Projects\TesteFinalSolution\Window.h"
#include "C:\Users\pc\Documents\Visual Studio 2010\Projects\TesteFinalSolution\GUI.h"

int main ()
{

using namespace Graph_lib;

Point t1(100,100);

Simple_window win(t1, 600, 400, "Canvas");

Image ii( Point(100,50), "C:\\Users\\pc\\Documents\\Visual Studio 2010\\Projects\\TesteFinalSolution\\TesteFinal\\Debug\\image.jpg");

win.attach (ii);

win.set_label("Canvas #11");
win.wait_for_button(); }


And instead of the image at that point I get the text cannot open "C:\\Users\\pc\\Documents\\Visual Studio 2010\\Projects\\TesteFinalSolution\\TesteFinal\\Debug\\image.jpg"



And the Output:

'TesteFLTK.exe': Loaded 'C:\Users\pc\Documents\Visual Studio 2010\Projects\TesteFinalSolution\Debug\TesteFLTK.exe', Symbols loaded.
'TesteFLTK.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18201_none_ec80f00e8593ece5\comctl32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'TesteFLTK.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'TesteFLTK.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Program Files\SearchProtect\SearchProtect\bin\SPVC32Loader.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
First-chance exception at 0x75b6812f in TesteFLTK.exe: Microsoft C++ exception: ?AV4378_________@@ at memory location 0x002ce2bc..
'TesteFLTK.exe': Unloaded 'C:\Program Files\SearchProtect\SearchProtect\bin\SPVC32Loader.dll'
'TesteFLTK.exe': Unloaded 'C:\Windows\System32\version.dll'
The thread 'Win32 Thread' (0x1f5c) has exited with code 0 (0x0).
'TesteFLTK.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\msimtf.dll', Cannot find or open the PDB file
'TesteFLTK.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
90% of those errors are simply because you are building your project in debug mode while trying to link to the release versions of the libraries for those DLL files. Either fix your linking or compile your project in release mode.

You still didn't fix the inclusion of the header file, or you didn't try it this time since it's Windows.h, with an 's' and I don't see the rest of the code I suggested.

It's kind of important to tell us that your application isn't even compiling. Fix the linkage, double check the headers and try again.
I already compile my project in release mode but the errors remained.
In this book, the header file that is available is"window.h" and not "windows.h".

I didn't put your code because of what I said before "It doesn't recognize TCHAR MyDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, MyDir); "


I think I'll give up and try to find someone who help me personally.

Thanks!
"window.h" and "windows.h" are two completely separate and unrelated header files. The first is part of the graphics package FLTK. The other is a header supplied in order to access facilities relating to the MS Windows operating system. For a computer running on the Windows OS, "windows.h" will be a standard part of the compiler headers. You need to include this in order to use such functions as GetCurrentDirectory
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364934%28v=vs.85%29.aspx
All I can think of your problem is the image file path. Have you ever checked out the correct style of the image file path. Or you can try to open image from stream to see whether it is ok for this operation, if yes, you have to check the local image file openting control.

http://www.rasteredge.com/how-to/vb-net-imaging/load-from-file/

http://www.rasteredge.com/how-to/vb-net-imaging/open-save-file/
Topic archived. No new replies allowed.