We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Anyone know how? Various Google searches, and I haven't found anything other than the code below. I just want to be able to select a .png file to be loaded into a PImage variable. Easy enough if you want to open a specific image, but I want the user to be able to open what image they want from a folder of images.
void fileSelected(File selection) { if (selection == null) { println("Window was closed or the user hit cancel."); } else { println("User selected " + selection.getName()); } }
void setup() { selectInput("Select a file to process:", "fileSelected"); }
Answers
Instead of printing selection.getName() to the console, pass it to loadImage()...?
Okay I found this https://forum.processing.org/one/topic/load-an-image-via-selectinput-and-then-set-sketch-size-to-its-dimensions-using-p2d.html
However, I don't know how to then run a function ON the image I load. What I used in the past, when I was loading a specific PNG file rather than allowing user to chose the file was this...
Yet how do tell it to loadImage() when the image is a now PImage name rather than a string like "filename.png:?
selection.genName() returns a String (the name of the file selected), not a PImage.
Once you pass that name to loadImage(), it will actually load the file for you, and that returns a PImage.
https://forum.Processing.org/two/discussions/tagged?Tag=selectinput()
I got the image to load, but now would like to know how to let user chose a different file. It amazes me how much information isn't on this website right up front. I'll go through that link GoToLoop, but why isn't there a ton of information on this on the site itself? Opening files seems something a bit common.
Hmm. I think there are reference pages, examples pages, bundled sketchbook examples, and tutorials on loading files.
For example, look on the Processing Reference page under Input > Files. There are 15 file input functions documented -- right now you want the last ones, plus anything starting with 'load' under other reference headings like Images.
https://processing.org/reference/