Problem loading a PImage from the sketchbook data directory, Windows 7

edited June 2015 in How To...

I cannot get my program to load an image from the data directory. If I place my image rooted to the C: directory, it will load (using loadImage). So, I figure the problem is not with the image. I have a .vlw file in my sketchbook data directory that reads fine. I tried changing the name of it to make sure that it was not coming from some other copy and that caused it to not be seen. I have used the add file function to place the image in the data directory (thinking that maybe it needed to get registered somehow). It asked if I wanted to replace the file that is there. I said yes, and so figure it did. I have checked the permissions of both the .vlw file (that reads fine) and the .png file that does not read fine from the data directory and can see no difference. I am out of ideas. Anyone know what I am missing?


  • Answer ✓

    Are you doing this loading inside setup(), after the call to size()?

    Post an small example of code that demonstrates your issue, please.

  • TfGuy44. You nailed it. I was defining my image in the global area and including the loadImage in that statement. With your question, I moved the loadImage to the setup area and that took care of it. Part of what had thrown me was that it would load (from the global area) if I gave it a direct path from the C: drive. Now I can't imagine why that was working in the first place. But, I'm not into figuring out why things I should not have done in the first place act like I would not expect. So, I'm set.

    Thanks a bunch

  • edited June 2015 Answer ✓

    Now I can't imagine why that was working in the first place.

    These Processing fields: (sketchPath, width & height) takes a little longer to be initialized properly.
    Therefore, if we try to access them before setup(), they still got no meaningful value yet. :-B
    That's why using any I/O functions, like loadImage() for example, fails. @-)
    Unless of course we provide some full path ourselves, since sketchPath is still null! :-@
    However, if we are using full paths, and specially web URLs, for loading stuff, it doesn't matter the place we call the loading function! :P

  • Thank you, GoToLoop for that explanation. That will be useful going forward.

Sign In or Register to comment.