We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, when i save the screen image, the result is a file with the correct name and the correct directory on my device, but the file is empy. This is my code:
void setup() { size(1200, 700); strokeWeight(4); background(255); textSize(30); rect(0,0,1200,700); rect(10,650,180,40); rect(1000,650,180,40); fill(0); text("CLEAR",40,680); text("FATTO",1040,680); }
void draw() { if (mouseY<640){ line(mouseX, mouseY, pmouseX, pmouseY);} if ((mouseX>10)&(mouseX<200)&(mouseY>650)&(mouseY<700)){ fill(255); noStroke(); rect(2,2,1195,645);stroke(0);} if ((mouseX>1000)&(mouseX<1200)&(mouseY>650)&(mouseY<700)){ fill(255); noStroke(); rect(2,645,1195,695); delay(100); saveFrame("/sdcard/infoconterm/firma.png"); delay(200); exit(); }}
I activated WR_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE.
Answers
Please edit your post, select code and hit ctrl+o so to format your code properly.
In regards to your question, try the following while saving the file:
String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath()); saveFrame(directory +"/"+"firma.png");
Other comments: Don't use delay within your draw. Using a thread would do a better job although not needed for this example.
I hope this helps,
Kf
Kf thanks. I have to do as you say me, but the result is the same.
This is my code with the change:
import android.os.Environment;
String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath()+"/infoconterm");
void setup() { size(1200, 700); strokeWeight(4); background(255); textSize(30); rect(0, 0, 1200, 700); rect(10, 650, 180, 40); rect(1000, 650, 180, 40); fill(0); text("CLEAR", 40, 680); text("FATTO", 1040, 680); }
void draw() { if (mouseY<640) { line(mouseX, mouseY, pmouseX, pmouseY); } if ((mouseX>10)&(mouseX<200)&(mouseY>650)&(mouseY<700)) { fill(255); noStroke(); rect(2, 2, 1195, 645); stroke(0); } if ((mouseX>1000)&(mouseX<1200)&(mouseY>650)&(mouseY<700)) { fill(255); noStroke(); rect(2, 645, 1195, 695); save(directory+"/"+"firma.jpg"); exit(); } }
This the file in the device;
This is the image content:
Sorry for the format. But with ctrl+o not copy.
This is the code:
import android.os.Environment;
String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath()+"/infoconterm");
void setup() { size(1200, 700);
strokeWeight(4);
background(255);
textSize(30);
rect(0, 0, 1200, 700);
rect(10, 650, 180, 40);
rect(1000, 650, 180, 40);
fill(0);
text("CLEAR", 40, 680);
text("FATTO", 1040, 680);
}
void draw() {
if (mouseY<640) {
}
if ((mouseX>10)&(mouseX<200)&(mouseY>650)&(mouseY<700)) {
}
if ((mouseX>1000)&(mouseX<1200)&(mouseY>650)&(mouseY<700)) {
}
}
@siomat -- Please:
This will make the code readable and copy-able.
I misread your question. I thought you wanted to save it in the external storage. I will encourage you to try other alternatives:
Try calling this function instead: https://processing.org/reference/saveFrame_.html
Or save a PGraphics object: https://processing.org/reference/createGraphics_.html
Or use a PImage object: https://processing.org/reference/PImage.html https://processing.org/reference/PImage_save_.html
Or you can try taking a screenshot. Some instructions at the end of this previous post: https://forum.processing.org/two/discussion/9893/save-images-in-specific-folders-android#latest
Kf
jeremydouglass, Sorry but in processing if i press press CONTROL + "o", The result is "Open a Processing Skech".
@siomat -- I'm sorry, I meant use CONTROL + "o" on the code in your posts here on this forum website so that it is readable.
If you do not do this then forum members cannot cut and paste your code to test it, because many linebreaks are missing, breaking the code and making it difficult to read.