Caprica Software

Picam 1.x Tutorial

Taking Pictures

Once you have a camera instance, it is simple to capture a picture.


Take Picture

Invoke the takePicture method to capture a picture from the camera.

This method takes a PictureCaptureHandler parameter - in this example the picture will be saved to disk:

MyCameraApplication.java
import uk.co.caprica.picam.Camera;
import uk.co.caprica.picam.CameraConfiguration;
import uk.co.caprica.picam.CaptureFailedException;
import uk.co.caprica.picam.FilePictureCaptureHandler;
import uk.co.caprica.picam.enums.AutomaticWhiteBalanceMode;
import uk.co.caprica.picam.enums.Encoding;

import java.io.File;

import static uk.co.caprica.picam.CameraConfiguration.cameraConfiguration;

public class MyCameraApplication {
public static void main(String[] args) {
CameraConfiguration config = cameraConfiguration()
.width(1920)
.height(1080)
.automaticWhiteBalance(AutomaticWhiteBalanceMode.AUTO)
.encoding(Encoding.JPEG)
.quality(85);
try (Camera camera = new Camera(config)) {
camera.takePicture(new FilePictureCaptureHandler(new File("photo.jpg")));
}
catch (CaptureFailedException e) {
e.printStackTrace();
}
// Camera will be automatically closed
}
}

Picture capture handlers will be explained in the next tutorial.