How do I change a saving path for outputted images?

edited November 2013 in How To...

Hi everyone, I'm new here.

I use Processing on Mac, and my program outputs screenshots of user-created drawings into the project folder at the press of the "P" button. This also works with the exported version on Mac.

For the Windows version, however, it's a different case. Pressing "P" doesn't put a screenshot in the project folder. It doesn't seem to be saved anywhere!

So, any ideas on how I would change the saving path? Saving to desktop would be a good alternative.

Thanks in advance!

Answers

  • Can you tell me how you're doing the screenshot? Is this Processing code, or an OS type of screenshot?

    -- MenteCode.

    P.S. Move this to How To please. it seems self-explanotory. ;)

  • MenteCode is right, I moved the topic because you asked this in the Questions about Code, but you don't show any code!

    In all versions of Processing, save() or saveFrame() puts the image in the sketch folder, so I am not sure why it doesn't work in Windows.

    Ensure your sketch is in a regular folder, not a virtual one like a Dropbox folder or similar.

    Otherwise, you can just give an absolute path to these functions (but then, it is no longer portable).

  • edited November 2013

    I was asking if this is an OS type of screenshot, because I've worked a bit on both systems, and I know that Windows won't save a screenshot to the desktop (or anywhere accessible, for that matter), but to the clipboard, while a Mac immediately saves it to the desktop.

    That's the only reason I can think of that it wouldn't work in all versions of Processing.

  • Hi, thanks for the quick replies. Sorry I tagged the question wrong.

    I am using save() like PhiLho said, and it does save it in the sketch folder. Even the exported version works on Mac! For some reason, it doesn't on PC though.

    Maybe it has to do with how Windows opens a folder compressed on a Mac?

  • Don't worry about it.

    Now that we know that it's not an OS screenshot, another factor comes into play. What file format are you using to save the sketch to image?

  • Actually, come to think of it, how are you attempting to save the sketch in the first place? Show what you're writing in the save() function.

  • The save function looks like this:

    save( "Drawkward" + str(Charc) + " - " + str(h) + ":" + str(mm) + ":" + str(s) + " -- " + str(d) + "-" + str(m) + "-" + str(y));

    An example of how that looks when I save it would be Drawkward1 - 13/41/53 -- 30-11-2013

    All of the variables are just to add a number/date to the image, so they don't overwrite old images. Also, since I didn't specify what type of file it saves as, it defaults to .tif.

  • Hmm... How could I change what kind of file it is? Maybe .tif is the problem.

  • edited November 2013

    I'm pretty sure if you read the console chat, you would've seen an error message.

    The results of my testing showed that it had nothing to do with the file format.

    The colons (:) are the ones causing the problem, as odd as it seems.

    It's because Windows restricts the use of characters in the range of ASCII codes 1-31 in a file name, and a colon is one of them. See the example below.

    String s;
    
    void draw() {
      s = "Drawkward" + " - " + hour() + " : " + minute() + " ; " + nf(second(), 2) + " -- " + day() + "-" + month() + "-" + year();
      line(10, height/2, 90, height/2);
      save(s);
      println(s);
    }
    

    Now here's the issue with this code. When you run THIS program, it will save. However, you'll see that the output looks like this: Drawkward - Current hour. That is because that 1 colon is acting as an if() statement which is always true, so all you see is what comes before the colon.

    Hard things simple: You CANNOT use colons at all, because it won't work, one way or another.

    -- MenteCode.

  • To add on, here's a rule of thumb. I recommend you avoid using any characters that can be typed by using the number keys along the top of the keyboard, in combination with the SHIFT key.

    That's a lot less than 31, but a lot of characters can be used in code.

  • Ah yes, I eventually figured this out too by testing a few things.

    Looks like I have something that works now! Thanks for your help!

  • edited December 2013

    "Drawkward1 - 13/41/53 -- 30-11-2013"
    Is that a legal name in MacOS? I doubt it, but well, it sure is an illegal name in Windows. Don't use / or other special characters.

    The list of illegal characters in a file name on Windows can be seen by renaming a file (select in File Explorer, hit F2, type : for example) with such character.

  • Here's a more accurate list of unusable characters, just for those wondering:

    http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words

Sign In or Register to comment.