Caprica Software

Picam 1.x Tutorial

Capture Handlers

There are many different ways to handle the picture capture data. You could simply get the "raw" byte array containing the picture data, you could create a BufferedImage, you could write the picture to disk, and so on.

You decide what to do with the picture data by using a PictureCaptureHandler. Some picture capture handler implementations are provided by picam but you are free to provide your own.

PictureCaptureHandler Interface

This is the definition for a picture capture handler:
public interface PictureCaptureHandler<T> {
void begin() throws Exception;
void pictureData(byte[] data) throws Exception;
void end() throws Exception;
T result();

The interface is a generic interface, the type parameter &lt;T&gt; represents the type of the object that the picture capture handler will return.

This could for example be a byte[], a File, a BufferedImage, a JFrame that can show the image, or whatever else you need.

begin() is called before the first capture data is retrieved, typical uses for this method would be to open a new file/stream, allocate a buffer and so on.

pictureData() is called when capture data is retrieved from the camera, this method is likely to be called multiple times and typical implementations would use this to write the picture data to a file/stream, or process the raw bytes in some other way.

end() is called after the last capture data is retrieved, typically implementations would clean up resources here like closing a file/stream.

The result() method can be used by your application to get the capture result.

PictureCaptureHandler Implementations

picam provides a number of picture capture handler implementations:

  • ByteArrayPictureCaptureHandler - capture picture data to a byte[]
  • FilePictureCaptureHandler - save captured pictures to a named File
  • SequentialFilePictureCaptureHandler - save captured pictures to a File with an automatic sequential numbering scheme

If you need a different implementation, implement it!