-
Notifications
You must be signed in to change notification settings - Fork 27
Using The Fluent API
The fluent API was introduced in version 1.1.0, it simplifies adjustment of settings for an RPiCamera
instance, and reduces the amount of typing required to do so, all while improving code readability.
To use the fluent API, you simply call subsequent set
methods on the return value of the prior method (note that only methods whic return RPiCamera
are eligible for this - but this includes most methods). For example, the following code demonstrates how a user might set up an RPiCamera
instance prior to the introduction of the fluent API.
RPiCamera piCamera = new RPiCamera("/home/pi/Pictures");
piCamera.setWidth(500);
piCamera.setHeight(500);
piCamera.setBrightness(75);
piCamera.setExposure(Exposure.AUTO);
piCamera.setTimeout(2);
piCamera.setAddRawBayer(true);
piCamera.takeStill("An Awesome Pic.jpg");
This approach still works - however, it can now be rewritten as follows...
RPiCamera piCamera = new RPiCamera("/home/pi/Pictures")
.setWidth(500)
.setHeight(500)
.setBrightness(75)
.setExposure(Exposure.AUTO)
.setTimeout(2)
.setAddRawBayer(true);
piCamera.takeStill("An Awesome Pic.jpg");
As you can see, backwards compatibility is in no way broken. However, use of the fluent API is advised, because it makes code easier to read and write.