As humans, we have emotions and feelings and one of the best ways to capture our emotions is to take pictures.
Some of our greatest experiences are actually captured in pictures. For sure each one of us have pictures from birthday parties, holidays, travels, conferences. We also like capturing feelings like happiness or reactions when bad surprises happen. And, in the latest years, we discovered that we love taking selfies.
The pictures help us evaluate how our life has changed, or they can help us to concentrate on a specific time or feeling.
These days the pictures do not necessarily need to be washed and printed out and to put into albums manually if we wish to keep a copy of memories, because now the photos are digital and can be stored in hard drives, cloud, or even to create online albums.
Currently, social media has improved the importance of photography. They enable us to express ourselves.
Facebook posts with images get 2.5 times more engagement (likes, shares & comments)
And lots of these photos are selfies—self-portraits, usually taken with a smartphone. As of this writing, nearly 300 million Instagram photos had been tagged with the selfie label.
Face-tracking studies show that the profile picture or avatar is the first place the eye is drawn to on Facebook and other social media profiles. So make sure you have a stellar profile picture.
On Instagram, pictures with human faces are 38 percent more likely to receive likes and 32 percent more likely to attract comments than photos with no faces.
We all know that a picture is worth a thousand words. And we actually feel the need to capture moments from our life, because photos help us to tell stories. Self-portraits are about self-image—how we define ourselves. There is also a psychological concept called the “looking-glass self” that says that how we see ourselves doesn’t come from who we really are, but rather from how we think others see us.
How many photos do you think are taken yearly?!
Now that we know how many photos are taken yearly, let’s see what devices are used to make these pictures, and we have 3 main categories: digital cameras, phones and tablets.
What is important to understand is that a big part of the photos are taken by using a phone.
2️⃣Challenges of using Camera APIs
Since we are android developers let’s see what are the challenges in terms of using the Camera APIs in building an app that takes photos.
There are 3 different kind of challenges.
- We must manage to build apps that work on different android versions. We have a lot of OS flavors since each year google launched a new android version
- The platform fragmentation. The apps we create are running on different kind of devices, and in terms of configuration and price there are entry level devices, mid-range devices and premium devices.
- Complexity of the Camera APIs
In terms of Camera APIs we have:
- The legacy one, or Camera 1 API which right now is deprecated.
- Camera 2 API was added in API level 21 (Android Lollipop). Indeed it added some improvements but in terms of using this API it implies to write a lot of code and to make sure the lifecycle of the camera session is well managed.
- At Google I/O, in 2019 CameraX was released. It is part of the Android Jetpack and it is actually a wrapper of Camera 2 API.
3️⃣Advantages of using CameraX API
Since CameraX is a wrapper for Camera 2 API it is compatible with L+ devices, which means Android 5 or Lollipop (API 21). So by using this API we cover about 90% of all Android devices.
CameraX provides an easy to use api and the purpose of this presentation is to show you how this api could be easily integrated in our apps.
📌Fewer lines of code
One of the first advantages of using CameraX vs Camera 2 is that the number of the lines written is reduced by 70%. There is a case study about Monzo that reduced over 9 thousands lines of code and improved registration dropout by 5x with CameraX.
Just like other Jetpack libraries, one of the core properties of CameraX is lifecycle awareness. Instead of having to manage the opening and closing of camera devices and sessions, CameraX takes care of this on our behalf as long as we provide a lifecycle owner. When the lifecycle starts, so does the camera; and when the lifecycle stops we don’t have to worry about closing either because CameraX does that for us.
Another core principle of the CameraX Jetpack Library is its use-case-driven approach. UseCase is actually an abstract class. An important thing to mention here is that each use case is fully independent. We could use only one of them or we could combine them.
📌Consistent behavior across devices
However, even if our app runs on the same API levels, there are a few things that can be different across devices. For example the HAL can have a big impact on performance. To solve this issue, the CameraX team has invested a lot in automated testing, including building a dedicated test lab with a big range of devices. All with the goal to have consistent behavior across devices.
Google uses a big amount of devices to test CameraX library. You could check the list of the devices here.
There are 52 different kind of devices representing 200 millions of active devices to have confidence in this library. Unit, integration and functional testing is applied to these devices and other than that CameraX is integrated in Lens Go which offers to Google the possibility to have feedback from a big amount of users.
In the next blog posts from this series we will talk about all use cases available in CameraX and also about vendor extensions. Until then let’s summarize the main advantages of using CameraX:
Enjoy and feel free to leave a comment if something is not clear or if you have questions. And if you like it please share !
Thank you for reading!
3 thoughts on “Smile, it’s CameraX! [intro]”
Hello. Great points explores. But to be practical …. Do you have an example with turn on/off flash While camerax is on ? And how about a watermark over the preview and after shot ? Tks.
Hello! In my second article about CameraX you will find a code example.
Pingback: Smile, it’s CameraX! [preview and capture] – Magda Miu