Skip to content

Creating an Instance of RPiCamera

Andrew Dillon edited this page Nov 24, 2016 · 3 revisions

RPiCamera is the central class of the JRPiCam API. To create an instance, use the following code:

try {
  RPiCamera piCamera = new RPiCamera();
} catch(FailedToRunRaspistillException e) {
  e.printStackTrace();
}

This code creates a default RPiCamera object. All images taken and saved with this instance will be saved to the "/home/pi/Pictures" directory (note that images are only saved if taken with the takeStill() method, all other take methods return the image in some form without saving it). The constructor of RPiCamera throws a FailedToRunRaspistillException if it was unable to find the raspistill program installed on the Pi.

If desired, the save directory of an RPiCamera can be changed by passing in a different path to the constructor, or via a method call:

//Pass a save directory to constructor
RPiCamera piCamera = new RPiCamera("/home/pi/AlternativeDirectory");

//Change save directory via a method call
piCamera.setSaveDir("/home/pi/AlternativeDirectory");
Clone this wiki locally