Problem whle loading image using PxLoadImage()


I am using PxLoadImage() to load the .jpg file.

My concern is that to what location should i copy the .jpg file so that it could be loaded from application and
displayed on screen.

Is PxLoadImage() load file from its default path and how can we modify that path.

Lets say:-

If i am using ETFS file system and my application image is at “fs/etfs”.
and this application is suppose to load the .jpg file and display on screen but my concern is that where i should place
the .jpg file so that it can be loaded.

Do I have to place the .jpg file at same location “fs/etfs” or somewhere else.

This seems to be a very silly doubt but Please help me…!!!

Thanks a lot


The application will use the current directoy as the base. The current directory is NOT where the binary is but rather were it was started from. This can be changed with chdir() what I like to do in my program is get the binary location with _cmdname() and then make every thing relative to that path.

Mario Thanks a lot…

I will implement your suggestion.

Still I am confused…!!
What if I don’t change the directory of my binary file <say , let it be fs/etfs>
than where I put my .jpg image so that it can be load and displayed.

once again thanks a lot


It doesn’t matter where the program is, it’s where you start it from that matters. If you binary and jpg are in /fs/etfs/ and before starting it you do cd /fs/etfs/ then if you progralm does a PxLoadImage and specify the jpg file without any path, then it will work.

If you do cd /fs and start the program by dont etfs/program then PxLoadImage won’t be able to load the image because it will try to find it in /fs.

Hello Mario…!!

I did what u suggested but still image is not loaded.

My application binary is in fs/etfs
and i copied *.jpg and *.bmp also at “fs/etfs” and “fs/usb”
here is the code which i am using–>

void loadimage(void)
int c,error;
char fname[255] = { 0 };
char *temp = “cd /fs/etfs/”;
char name[30];

PtArg_t     arg[5];
PtWidget_t  *window;

PhImage_t   *img;
    PxMethods_t methods;

memset( &methods, 0, sizeof( PxMethods_t ) );

fprintf(stderr,"\nin loadimage");

methods.flags |= PX_LOAD;

fprintf(stderr,"\npath = %s\n",_cmdname(fname));

chdir(temp); /*here i am try to change the path as "cd /fs/etfs"*/

fprintf(stderr,"\npath_aftr change = %s\n",_cmdname(fname)); 

sprintf(name,"image6.bmp"); /*image name which i want to load*/

if( ( img = PxLoadImage( name,&methods) ) == NULL )
        fprintf( stderr, "\n\tError loading/query");

       		PtExit( EXIT_FAILURE );

PtSetResource (ABW_PtLabel1, Pt_ARG_LABEL_IMAGE,img, 0 );

PtFlush ();


in loadimage
path = /fs/etfs/./anim

path_aftr change = /fs/etfs/./anim

    Error loading/query

/output ends*****/

/code ends************/
And also I tried by change the directory path by changing the variable as

char *temp = “cd /fs/usb/”;

still i am receiving the same output

Please let me know What i am doing is right ?

If not please guide me…

Thanks a lot


char *temp = “/fs/usb/”;


Thanks a lot

char *temp = “/fs/usb”;

it won’t work…!!

and even i tired for
char *temp = “/fs/etfs”;
that also won’t work.

Is there any other are where i can concentrate to find what went wrong.


Instead of: chdir(temp); /here i am try to change the path as “cd /fs/etfs”/
Use: system(temp); /here i am try to change the path as “cd /fs/etfs”/

Don’t use system()… This will not work, at all.

First you should always check return values, for exemple did the chdir() worked?

I also suggest you re-read the documenation as you seems to have misunderstood how thing works. _cmdname show the path of the executable, chdir() has no effect on that.

Maybe if you print the value of errno when PxLoadImage fail it would give you some extra clue has to what is going on.

What if you try to do and open() on the file, does that work. Maybe it’s something else that having access to the file that makes PxLoadImage. What if you try to provide full path to PxLoadImage( “/fs/etfs/image6.bmp” …) does that work ?

Sorry Mario, but
chdir( “cd /fs/etfs” ) does not make sense, as the argument has to be a path.
system(“cd /fs/etfs”) will change to the specified directory. This works always!
Just make sure your process has the permission to operate with /fs/etfs.
Could you please list /fs directory: “ls -l /fs”, and also list you executable “ls -l your_program”

I never said anything about chdir(“cd /fs/etfs”), the OP is the one that came up with that ;-) I would not expect system(“cd …” ) to work. Even if it does work it’s a bad idea, it’s hard to handle error, it’s slower, it’s less real-time etc.

I would not expect it to work ( although I haven’t tried it myself ) because when you call system you invoke a shell, which in turn runs the cd command, and thus changes the current directory of that shell. I don’t beleive a child can affect the parent’s current directory. Otherwise imagine this, a process start, which spawn another proces, which spawn another one. Now the 3 programs are happily running and then the third process does chdir() or system (“cd …” ). If that change would propagate up to the 3 processes, chaos would ensue ;-)

list of /fs—>

ls -l /fs

total 8
drwxrwxr-x 3 0 0 0 Oct 08 11:53 etfs
drwxrwxrwx 9 0 0 4096 Jul 19 13:21 usb

list executable →
#ls -l /fs/etfs /as my all executable lies here/
total 930
-r–r–r-- 1 0 0 2048 Aug 24 15:55 .badblks
-r–r–r-- 1 0 0 8192 Aug 24 15:55 .counts
-r–r–r-- 1 0 0 2048 Aug 24 15:55 .filetable
-r–r–r-- 1 0 0 0 Aug 24 15:55 .reserved
-rw-rw-rw- 1 0 0 13356 Aug 20 13:18 ADStest
-rwxrwxrwx 1 0 0 10533 Sep 03 18:27 adctest
-rwxrwxrwx 1 0 0 10165 Sep 06 14:44 adctest1
-rwxrwxrwx 1 0 0 16673 Oct 08 12:28 anim /I am using this binary/
-rw-rw-rw- 1 0 0 284 Sep 21 09:23 display.conf
-rwxrwxrwx 1 0 0 9513 Sep 02 19:09 gpio0test
-rw-rw-rw- 1 0 0 35578 Oct 05 19:44 image1.jpg /i am trying to display this image/
-rw-rw-rw- 1 0 0 242878 Oct 05 12:24 image6.bmp
-rwxrwxrwx 1 0 0 8595 Sep 02 15:04 keypad0test
-rwxrwxrwx 1 0 0 8885 Sep 02 13:20 keypadtest
-rw-rw-rw- 1 0 0 65 Sep 20 16:39 t2
-rw-rw-rw- 1 0 0 65 Sep 20 13:33 te
-rwxrwxrwx 1 0 0 35738 Oct 04 19:23 temp
-rwxrwxrwx 1 0 0 28533 Sep 23 15:11 temp1
-rw-rw-rw- 1 0 0 65 Sep 21 15:51 tempcalib
-rw-rw-rw- 1 0 0 65 Sep 20 13:22 tes1
-rw-rw-rw- 1 0 0 65 Sep 17 17:14 tes11
-rwxrwxrwx 1 0 0 26942 Sep 17 12:41 test

I also tried “system(temp)”
but it won’t work…!!

Where is the problem still it is uncleared to me…


Hello Mario,

I won’t get any clue regarding the error
and also by giving full path “/fs/etfs/image6.bmp” to the PxLoadImage( “/fs/etfs/image6.bmp” …)
it also won’t work.


What do you mean by "I wont get any clue regarding the error", If you give full path and it doesn't work then it becomes obvious its not a path issue.

Have you tried loading the file with open as was suggested to you. If you print the value of errno after PxLoadImage fails what is its value. If you use pv ( Photon Viewer) to load the file does it work ( pv used PxLoadImage() ). PxLoadImage needs some special .so files to work maybe you haven`t install them properly if your target is a custom made image.

As always you have right Mario. You are the Master.
PxLoadImage uses for jpeg files.
Try to load BMP file( instead of JPEG ). It uses

That’s pre 6.5.0. With 6.5.0 it has changed it’s now called img_codec_*.so and there is a file called /etc/system/config/img.conf that required.