Can I start processing without opening a window?

edited October 2016 in Questions about Code

So it's something very basic, but I really wonder if there is a way to do it, as I searched for a while without success. My purpose is to manipulate image files. So, I don't need anything to be displayed until I choose a file. Once done, I want the image to be displayed with the proper dimensions. Here is the very simple code for that, but I can't get rid of the first window of 600x600 pixels, so maybe you know a way to do that?

PImage loadedImgage;
String selectedPath = "";

void fileSelected(File selection) {
  selectedPath = selection.getAbsolutePath();
}

void setup() {
  size(600, 600);
  selectInput("Select a file to process:", "fileSelected");
}

void draw() {  
  if(selectedPath != ""){
    loadedImgage = loadImage(selectedPath);
    image(loadedImgage, 0, 0);
  }
}

Answers

  • Thank you GoToLoop, but what am I supposed to understand here? It's obviously far from what I need, unless there is part of that issue which is linked - but which part, and what solution, I'm sorry but I'm very confused about that.. So if you can elaborate a little more it would be very nice

  • It's obviously far from what I need, ...

    So cut out what you don't need. Post your most updated attempt here afterwards.

  • edited October 2016

    Hi again, I still don't know what you mean, as I told you, the linked article contains many things unrelated to what I asked in my first post. So please I'd be grateful if you can help me thru simple sentences, if you can, otherwise don't bother to answer.

  • Answer ✓

    These are some of the things you've asked for:

    So, I don't need anything to be displayed until I choose a file.

    Once done, I want the image to be displayed with the proper dimensions.

    My example does those 2 things above. So I'm at a loss what exactly is being asked here. :-??

  • Is your use scenario here related to the one in this thread?

    @GoToLoop linked to sketch code. That code seems to do exactly what you are asking for in this thread, without modification. Just paste the code into Processing and hit Run: as you'll see, it first completes the image load dialog and then launches the sketch window, showing the chosen image.

    Combine @GoToLoop 's answer with @koogs answer on saving, and you seem to have both problems solved. What part is missing / unclear?

  • Hi GoToLoop and jeremydouglas, thanx both of you for your answers, haven't had time to look back to this until today, and yes, the post contains the answer, even if it wasn't that clear at the beginning.

    Though, I have a question regarding the code found here : https://forum.processing.org/two/discussion/16705/null-pointer-exception-when-loading-image-in-settings-p3-1-1#Item_1

    What is the purpose of lines 16, 17 : noSmooth(); noLoop();

  • edited October 2016 Answer ✓

    Because the default behavior of Processing is an animation tool, draw() is normally called at a framerate, e.g. looping at 60 frames per second. noLoop() turns this off; draw() is only called once (unless loop() turns it back on again. See this example.

    noSmooth() controls antialiasing; you don't need it and it isn't directly relevant to your problem.

    You can look up all these terms you have questions about in the Processing IDE by right-clicking on one and selecting "Reference".

  • Thanx a lot jeremy for these details, I'll check that indeed if I need it, but for the moment it works fine that way. All the best

Sign In or Register to comment.