We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone,
In my small program, the user selects an image file and then the file can be seen in full screen, I have made some mistakes in my code:
import java.io.File;
import processing.opengl.*;
PImage img;
int mX, mY;
void setup() {
size(640, 200);
background(0);
selectInput("Select a file to process:", "fileSelected");
}
void draw() {
stroke(255);
if(mousePressed) {
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
void fileSelected(File selection) {
image(img, 0, 0);
img = loadImage(selection.getAbsolutePath());
}
but it does not work, where I'm wrong? Another question: how can I directly open the browser in the folder where is the code?
thanks!
Answers
https://Processing.org/reference/selectInput_.html
https://forum.Processing.org/two/discussions/tagged?Tag=selectinput()
thanks for the link GoToLoop, but I do not find the solution to my problems. If you have time, or someone helps me to understand how to solve, Thank you in advance.
https://forum.Processing.org/two/discussion/16705/null-pointer-exception-when-loading-image-in-settings-p3-1-1#Item_1
in simple terms, the program doesn't wait for the user to select a file.
you should also catch the situation when user hit cancel in the dialogue :
Obviously you can't also display an image before loading it. Without loading it, img is still empty!!!
so this
must be
this might even work surprisingly, since you don't use background in draw(). If you would, you would use
image(img, 0, 0);
in drawGoToLoop, I understand that the problem is "null pointer exception"
your code GoToLoop:
does not work with Processing 3.3 you can fix it?
Thanks Chrisir for having me explain an important aspect of my mistake. I have done the changes that you've recommended, but it does not work, I have error: "Null pointer exception", you can solve it?
thank you all.
Have you even tried it out? Just copied & pasted it in my PDE 3.3 and it's simply worked here! 8->
BtW, the code you've posted is mal-indented. L-)
GoToLoop, I'm sorry for how I've posted the code.
You're right, your example works well. For a few minutes my PC would not open the execution of the file in the window, and I thought of a problem with the file, sorry again.
I've added to your code the option to draw lines with the mouse, but I see nothing,
I doing something wrong?
What is the directory to be added to open the "Browser" in the folder where the file is currently running?
thanks
hit ctrl-t in processing to auto-format the code (indents!!!!) prior to posting it here
to tell the load dialogue the folder use
selectInput
with 3 parameters:why do you use
noLoop()
? Don't.not sure we can use size after the whole thing but I think gotoloop is in the lead.