Load image files from external storage to PImage

edited September 2016 in Android Mode

Hey, im having some trouble loading images to PImages inside a android processing sketch. Here`s the code, based on this thread https://forum.processing.org/two/discussion/9893/save-images-in-specific-folders-android#latest

import android.os.Environment;

PImage img;

void setup(){
  String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Atelie");

 img = loadImage(directory + "img2.png"); //i have also tried "/img2.png"
 image(imagem, 0, 0);

void draw(){
image(img, 0, 0);

The images are on a folder called Atelie that I have created using android file transfer, and I can see them in my mobile.

The sketch compiles, install, and crashes as soon as it opens, probably because it is not finding the file, no console erros.

The Read External Storage permission is marked.

Im using processing 3.2.1, Android mode 4.0-beta2, API 23, Asus Zenphone 2 Laser android 5.0.2

thanks in advance


  • Answer ✓

    It is actually loading when I put "/img2.png" .. sorry for wasting your time =(

  • Not a problem! I've made that mistake often.

    To keep my filenames separate (for if I make them a parameter), I'll often use a form with a separate slash:

    loadImage(directory + "/" + "img2.png");

    Also, you can use debug mode and set a breakpoint on the line -- but when I'm having a path problem, I'll often just add a println just before the path directive with identical contents:

    println(directory + "img2.png");
    loadImage(directory + "img2.png");

    That will usually show you exactly what is going wrong (e.g. trying to load "myfolderimg2.png").

Sign In or Register to comment.