Processing Cannot Load Image Even Though It Exists

edited December 2015 in Programming Questions

I am working on a Processing sketch that saves a picture of the sketch and then uses the picture. The sketch was originally written with Processing 2, but I am now attempting to port the sketch to Processing 3. Although I've managed to get most of the sketch working, I have one remaining problem: although Processing saves the image just fine, it reports that it cannot load the image. Here's the output from the console:

The file "C:/fakepath/file1image.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

Note: The file path is not actually "C:/fakepath/file1image.png", I modified the output when posting here.

Aside from this message, I do not receive any other output, and where the image would normally appear in the sketch, nothing appears at all. The only way I can get the image to appear is by closing the sketch and reopening it.

The project is over 8,000 lines long, so I am unable to post an example of the code at the moment. I will work on pulling out a sample of the code for testing purposes now.

I am using requestImage() to load the image. I previously used loadImage(), but I found that the sketch would freeze and crash when attempting to load the image.

Tagged:

Answers

  • Is there particular reason why you use absolute path? Did you try to load images from sketch's data folder?

  • You don't need to post the entire thing - try to recreate the problem using a tiny sketch and post that instead.

  • I am using absolute paths because the sketch does not use a data folder. When in development, I use absolute paths and when I export the sketch, I place all of the necessary files in the library folder that is created. The sketch has a developer mode that I enable when working on the sketch and disable when exporting the sketch.

  • edited December 2015

    which OS ?

    did you try double slash instead of single slash?

    this works Win 10 and processing 3

    size(800, 800);
    
    PImage a1 = loadImage("C://Users//ffsudgfdugz//Documents//Processing All//4ForumProcesCA_CN//classPVector1//img1.jpg"); 
    
    image(a1, 0, 0);
    
  • and this doesn't work

    size(800, 800);
    
    PImage a1 = loadImage("C:/Users/ffsudgfdugz/Documents/Processing All/4ForumProcesCA_CN/classPVector1/img1.jpg"); 
    
    image(a1, 0, 0);
    
  • I am on Windows 10, but it does not seem to make a difference whether I use the single or double slash. The behavior is the same.

  • Hey I know your problem, you are supposed to use a double slash but this kind of slash "\" not this kind "/" had the same problem and figured out on accident really.

  • edited December 2015

    I am still getting the error even after changing all of them to "\\".

  • Hmm, really? can you repost your code please? And what kind of computer do you have again?

  • I'm working on making a simplified version of the sketch now, as the actual sketch is over 8,000 lines long.

  • edited January 2016

    Here's a sketch that replicates the problem I've been having. The sketch does not draw the image because apparently that's not part of the problem.

    File image = new File("C:\Users\David\Desktop\image.png"); String imageString = "C:\Users\David\Desktop\image.png"; PImage pimageV;

    File image = new File("C:\Users\David\Desktop\image.png"); String imageString = "C:\Users\David\Desktop\image.png"; PImage pimageV;

    void setup() { size(700, 600); saveFrame(imageString); pimageV = requestImage(imageString); }

    Sorry, I cannot figure out what the markup is to add the code box. For a view of the code that isn't sloppy, see pastebin.com/7WepWrFC.

  • Because I don't have your pictures, I can't really test this out, but try to call saveFrame(imageString); pimageV = requestImage(imageString); in void draw ?

  • The pictures are created when the sketch is run. The sketch does not use any preexisting pictures. I also do not call that portion of code from setup() in the actual sketch, but it was put there in the demo sketch to make things easier. In the actual sketch, it's called from mousePressed(). Regardless, the problem replicated in the demo sketch is identical to the original.

  • If that didn't fix it, I really don't know, because I just know that I had your similar problem when trying to make my path and it worked by using \ but you said that wasn't it. Maybe you typed in the name wrong of the file? I also know that sometimes Processing gets REALLY picky, so is your file a ".png" or ".PNG" cause I had an issue with that and changing the case of the letters helped for some reason.

  • That's just it, I checked to make sure that I did not screw up the file path, and I did not. The fact that this was not an issue with previous iterations of Processing (all previous iterations that I am referring to are Processing 2) makes me wonder if this is not an issue with my sketch, but rather an issue with Processing.

Sign In or Register to comment.