APDE
APDE copied to clipboard
How do I use file FROM the phone
I'm trying to make something to find an image on the phone (eg. Test.jpg) and as far as the reference goes I can use the file path, but either I don't know the path or doing somthing wrong
This is my code so far
PImage webImg;
void setup() { size(400,400); String url = "/Testfolder/Test.jpg";
webImg = loadImage(url); }
void draw() { background(0);
image(webImg, 0, 0);
}
Are you on Android? If so: /storage/emulated/0/testfolder/ would be your path
PImage webImg;
void setup() { size(400,400); String url = "/storage/emulated/0/testfolder/test.jpg"; // Load image from a web server webImg = loadImage(url); }
void draw() { background(0); image(webImg, 0, 0); }
I tried it and it still crashed the sketch and I am on Android
It says all of this
Failed to delete old APK file java.io.IOException: Stream closed at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:152) at java.io.BufferedInputStream.fill(BufferedInputStream.java:239) at java.io.BufferedInputStream.read1(BufferedInputStream.java:279) at java.io.BufferedInputStream.read(BufferedInputStream.java:338) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:1044) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:961) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:1076) at processing.core.PApplet.loadImage(PApplet.java:3992) at processing.test.testingimages.testingimages.setup(testingimages.java:25) at processing.core.PApplet.handleDraw(PApplet.java:1801) at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:471) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:503) Could not load the image because the bitmap was empty. java.lang.NullPointerException: Attempt to read from field 'int processing.core.PImage.width' on a null object reference in method 'void processing.core.PGraphics.image(processing.core.PImage, float, float)' at processing.core.PGraphics.image(PGraphics.java:2843) at processing.core.PApplet.image(PApplet.java:8707) at processing.test.testingimages.testingimages.draw(testingimages.java:30) at processing.core.PApplet.handleDraw(PApplet.java:1818) at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:471)
The images have to be placed inside Sketchbook -> Projectfolder -> data. So you should use: loadImage("test.jpg").
Under Settings -> General you can choose the sketchbook location:
But I want to use photos from anywhere on the phone by just renaming or moving it to a not data folder
Hey @Turtlemod , in plain processing you would do it like this for the '"just outside" folder named '0texts'
"../0texts/m3.txt"
I mean you aren't putting stuff inside 'data' but on a folder called '0texts' that is one level up the folder of your sketch, so you have, '0texts' with your sketch folder besides on the same level. I think you can use '../../ **' to go up more levels, but I'm not that much unoccupied to test that for you, sorry... good luck
@Leamucho By same level you mean like this
And just to clarify I want to use the "testfolder" to hold images and then this uses it