Once you have a configuration object, the next step is to create a camera instance.
Camera creation is straightforward, using the configuration from the previous tutorial:
This code simply creates a new
Camera instance, passing the configuration via
a constructor parameter.
You could implement this in a slightly more compact way:
In the above code, the intermediate step of creating the camera configuration has been combined with creating the new camera instance.
Whichever implementation you choose makes no difference, it is simply a matter of which code style you prefer.
The camera instance should be closed when you no longer need it:
You could use "try-with-resources" and the camera instance will be automatically closed:
If your application is going to take more than one picture, it is recommended that you create the camera instance once and keep it open for as long as you need it - do not create a camera, take a picture, close the camera, create a new camera, take a picture, and so on...