Created
March 6, 2016 11:39
-
-
Save dattasaurabh82/0fa95289d93e0b4b7586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Environment; | |
PImage img; | |
PImage imgTwo; | |
String directory = ""; | |
String filename = "beloved.jpg"; | |
void setup() { | |
size(displayWidth, displayHeight); | |
orientation(PORTRAIT); | |
background(0); | |
img = loadImage(filename); | |
} | |
void draw() { | |
if (imageStatus == false) { | |
background(0); | |
image(img, 10, 20); | |
} else { | |
background(0); | |
image(img, 10, 20); | |
loadFromPhone(directory); | |
} | |
} | |
//String tobeSavedFile = ""; | |
void saveImage(String tobeSavedFile) { | |
try | |
{ | |
directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myFolder"); | |
File myFolder = new File(directory); | |
boolean success = true; | |
if (!myFolder.exists()) { | |
success = myFolder.mkdirs(); | |
} | |
//save(directory + "/" + "image.jpg"); | |
img.save(directory + "/" + tobeSavedFile); | |
println("File saved successfully at : " + directory); | |
} | |
catch (Exception e) | |
{ | |
println("Error while saving file: " + e.getMessage()); | |
} | |
} | |
int counter = 0; | |
boolean imageStatus = false; | |
void mousePressed() { | |
counter++; | |
if (counter == 1) { | |
saveImage(filename); | |
println("Done saving"); | |
imageStatus = false; | |
; | |
} else if (counter >= 2) { | |
println("loading from phone"); | |
//loadFromPhone(directory); | |
counter = 0; | |
imageStatus = true; | |
} | |
} | |
void loadFromPhone(String newPath) { | |
if (newPath.length() > 2) { | |
imgTwo = loadImage(newPath + "/" + "beloved.jpg"); | |
image(imgTwo, width/2, height/2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment