We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys! Need some help!
I am trying to use save frame to take a screenshot of a plot I have currently programmed with processing. The plot GUI has several Buttons (made with Cp5) and Toggles. I have set a function which is being called when a button is pressed. However, sometime the frame I take comes with the cp5 buttons GUI but sometimes doesn't. So some frames have the buttons but some don't. For example:
Hope, you can see the frames. The code I use for the button is:
Button b1 = cp5.addButton("takeScreenShot").setPosition(z, w).setSize(100, 80);
b1.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_PRESSED):
if (flag) {
println("Taking photo...");
takeScreenShot();
}
break;
case(ControlP5.ACTION_RELEASED):
println("Done");
flag = true;
break;
}
}
}
);
and the function called for the takeFrame():
void takeScreenShot() {
String photoDate = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss").format(new Date());
String Date = new SimpleDateFormat("yyyy_MM_dd").format(new Date());
int m = millis()/1000; //for seconds
saveFrame("C:/Users/. . . .. . ./data/"+ Date + "/photos/" + "/manual/"+ photoDate + String.valueOf(m)+ ".jpg");
}
Is there any suggestions on how to tackle this problem?? I would appreciate any help, and any clarifications if needed.
ps. If the photos don't show, the buttons from cp5 configurations sometimes show sometimes don't. Can't find any reason why.!
Answers
Place
println(Thread.currentThread());
statement inside takeScreenShot().If it doesn't output
[Animation Thread,5,main]
, you probably shouldn't use saveFrame() there maybe. :-??Thanks for the Fast reply man! It is an honor B-) .
I could see the output before as well. There is still the same inconsistency as before. Sometimes with the Textfields, sometimes not. The output:
2017_05_10-18_11_22ControlP5 2.2.6 infos, comments, questions at http://www.sojamo.de/libraries/controlP5 Taking photo... Taking photo... Done Taking photo... Taking photo... Done Taking photo... Taking photo... Done Taking photo... Taking photo... Done Taking photo... Taking photo... Done Taking photo... Taking photo... Done
The only difference is that the println() comes twice.
Just understood what you meant. My bad. Newbie here! That's the output.
2017_05_10-18_58_11ControlP5 2.2.6 infos, comments, questions at http://www.sojamo.de/libraries/controlP5 Taking photo... Thread[Animation Thread,5,main] Thread[Animation Thread,5,main] Done Taking photo... Thread[Animation Thread,5,main] Thread[Animation Thread,5,main] Done Taking photo... Thread[Animation Thread,5,main] Thread[Animation Thread,5,main] Done Taking photo... Thread[Animation Thread,5,main] Thread[Animation Thread,5,main] Done
Seems fine I guess. Except the "Thread" ahead of it. Do you have any other suggestions?
What is the functionality of the flag field in line 7?
One suggestion is to set the cp5 autoDraw as false, and reDraw them manually and make sure you call takeScreenShot right after the controlP5 object is drawn.
Kf
The flag is supposed to make only one image with each mouse press. Otherwise if you keep the button pressed it would fill with subsequent photos. Therefore the flag(== Boolean) only allows one call of takeScreenShot() function
Thanks! Tried to check the autoDraw command and got to this thread. Thanks for the help guys.
https://forum.processing.org/two/discussion/3441/show-controlp5-controllers-in-screenshots