saveFrame("/sdcard/img-###.png") fails to be executed at Android Application

edited January 2014 in Android Mode

Hello dudes,

I am a newbie in using the Processing Language. I have developed a small application which displays randomly circles on the phone screen. Their radius is also one of the first 20 fibonacci numbers in magnitude. I have added a mousePressed() event in order to save my creations. However, my app closes instantly when I touch the screen with my finger. Can you help me in order to solve this problem?

My code:

void setup() {
 size(displayWidth,displayHeight);
 smooth(); 
 background(random(255),random(255),random(255));

}


void draw() {
  noFill();
  stroke(255);
  strokeWeight(4);
  for(int i=0; i<20; i++) {
    ellipse(random(width),random(height),fibonacci(i)/5,fibonacci(i)/5);
    delay(10);
  }


}

int fibonacci(int n) {
 if (n==0 || n==1) {
  return 1;  
 } 
 return fibonacci(n-1)+fibonacci(n-2);

}

void mousePressed() {
   saveFrame("/sdcard/img-####.png");
 }  


void delay(int ms)
{
   try
  {    
    Thread.sleep(ms);
  }
  catch(Exception e){}
}

The Android API I am using is the one recommended by the Processing Wiki.

Thanks in advance!

Answers

  • edited January 2014 Answer ✓

    Have you enabled the permission WRITE_EXTERNAL_STORAGE (Android > Sketch Permissions from the PDE)?

    Also, that may not be the correct path, depending on your phone. If it still doesn't work, then you can try this to save to the pictures directory:

    saveFrame(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/img-####.png");
    
  • I'll try it later in the evening! Thank you very much!

  • It saves a frame but not my frame .. It's just random something black screen. .

Sign In or Register to comment.