We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am trying to save a picture (save() or saveFrame() to Sdcard. The file is empty. Everything works fine in Java mode.
I have enabled the permission - WRITE_EXTERNAL_STORAGE I can save .txt file but problem is with pictures. The file has 0kB size.
Here's my simply code.
import controlP5.*;
ControlP5 cp5;
PImage backgroundImg = null;
void setup()
{
size(displayWidth, displayHeight);
backgroundImg = loadImage("backImg.jpg");
backgroundImg.resize(width, height);
backgroundImg.loadPixels();
cp5 = new ControlP5(this);
cp5.addButton("savePicBut")
.setBroadcast(false)
.setPosition(30, 30)
.setSize(30,30)
.setLabel("Save")
.setBroadcast(true);
}
void draw()
{
background(backgroundImg);
}
public void savePicBut()
{
saveFrame("//sdcard/PicTest.png");
String[] words = {"test1","test2","test3"};
saveStrings("//sdcard/words.txt",words);
}
Thanks a lot for your help. Sebastian
Answers
https://forum.Processing.org/two/discussions/tagged/write_external_storage
https://forum.Processing.org/two/discussions/tagged/sdcard
Thanks, but there is no answer for my problem. I can save strings (.txt file) to SdCard. It's ok. I cannot save picture (.jpg/.png file) to SdCard.
PS.I am using Processing 3.0.1
I've got a solution. I need to use get() function.
public void savePicBut() { ... PImage screenShot = get(); screenShot.save("//sdcard/PicTest.png"); ... }
If you need to take a picture from PGraphics just call
pg.get()