Home » Java » Image Paths in Processing Java-Exceptionshub

Image Paths in Processing Java-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m just curious when loading an image into Processing (Through Java) can I use a path name for an image? I plan to seperate my code and images into seperate folders and I was wondering if I could specify that. See code below:

import processing.core.PApplet;
import processing.core.PImage;
import ddf.minim.analysis.*;
import ddf.minim.*;

public class MusicVisual extends PApplet
{   
    Minim minim;
    AudioPlayer Music;
    AudioMetaData meta;
    BeatDetect beat;
    int r = 200;
    float rad = 70;
    PImage IMG;

    public void settings()
    {
        size(1280, 960);
        IMG = loadImage("Image.png");
    }

So instead of the line IMG = loadImage("Image.png"); could I perhaps say IMG = loadImage("../Data/Images/Image.png");

The only reason is because I want this to be a background for an audio visualizaer.

Thank you

How to&Answers:

Yes, you can, as long as you use an absolute path. From loadImage() documentation:

The file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows)