SlideShare a Scribd company logo
CameraX JetPack
Android Developers day Jakarta 2019
Hassan Abid, GDE Android
Twitter, Instagram, Github : @hassanabidpk
What’s new in JetPack Library
- Alpha
- CameraX
- LiveData and LifeCycle w/ coroutines
- Benchmark
- Security
- ViewModel with SavedState
- ViewPager2
- Beta
- ConstraintLayout 2.0
- BioMetric Prompts
- Stable
- JetPack Compose
- WorkManager
- Navigation
CameraX
Introduction
- Backward compatible with L+ devices
- Consistent behavior across devices
- Easy to use APIs
- Based on Camera2 Apis but hides Hardware layer
- Using CameraX results 70% fewer lines of code vs Camera2
Issues tackled
- Front/back camera switch crashes
- Optimized camera closures
- Incorrect Orientation
- Flash not firing
CameraX API (alpha)
- Preview
- Image Analysis
- Image Capture
Deep dive into CameraX
Preview API
Preview API
val previewConfig = PreviewConfig.Builder().build()
Preview API
val previewConfig = PreviewConfig.Builder().build()
val preview = Preview(previewConfig)
Preview API
val previewConfig = PreviewConfig.Builder().build()
val preview = Preview(previewConfig)
val textureView: TextureView = findViewById(R.id.textureView)
Preview API
val previewConfig = PreviewConfig.Builder().build()
val preview = Preview(previewConfig)
val textureView: TextureView = findViewById(R.id.textureView)
// The output data-handling is configured in a listener.
preview.setOnPreviewOutputUpdateListener { previewOutput ->
textureView.surfaceTexture = previewOutput.surfaceTexture
}
Preview API
val previewConfig = PreviewConfig.Builder().build()
val preview = Preview(previewConfig)
val textureView: TextureView = findViewById(R.id.textureView)
// The output data-handling is configured in a listener.
preview.setOnPreviewOutputUpdateListener { previewOutput ->
textureView.surfaceTexture = previewOutput.surfaceTexture
}
// The use case is bound to an Android Lifecycle with the following code.
CameraX.bindToLifecycle(this as LifecycleOwner, preview)
CameraX Lifecycles
CameraX Lifecycles
- CameraX observes a lifecycle to determine camera states
- When to open and close session
Image Analysis API
Image Analysis API
val imageAnalysisConfig = ImageAnalysisConfig.Builder()
.setTargetResolution(Size(1280, 720))
.build()
Image Analysis API
val imageAnalysisConfig = ImageAnalysisConfig.Builder()
.setTargetResolution(Size(1280, 720))
.build()
val imageAnalysis = ImageAnalysis(imageAnalysisConfig)
Image Analysis API
val imageAnalysisConfig = ImageAnalysisConfig.Builder()
.setTargetResolution(Size(1280, 720))
.build()
val imageAnalysis = ImageAnalysis(imageAnalysisConfig)
imageAnalysis.setAnalyzer({ image: ImageProxy, rotationDegrees: Int ->
// insert your code here.
})
Image Analysis API
val imageAnalysisConfig = ImageAnalysisConfig.Builder()
.setTargetResolution(Size(1280, 720))
.build()
val imageAnalysis = ImageAnalysis(imageAnalysisConfig)
imageAnalysis.setAnalyzer({ image: ImageProxy, rotationDegrees: Int ->
// insert your code here.
})
CameraX.bindToLifecycle(this as LifecycleOwner, imageAnalysis, preview)
Image Capture API
Image Capture API (Simplified)
val imageCaptureConfig = ImageCaptureConfig.Builder()
.setTargetRotation(windowManager.defaultDisplay.rotation)
.build()
val imageCapture = ImageCapture(imageCaptureConfig)
CameraX.bindToLifecycle(this as LifecycleOwner,
imageCapture, imageAnalysis, preview)
Image Capture API (Advance)
val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
setLensFacing(lensFacing)
setCaptureMode(CaptureMode.MIN_LATENCY)
// We request aspect ratio but no resolution to match preview config but letting
// CameraX optimize for whatever specific resolution best fits requested capture mode
setTargetAspectRatio(screenAspectRatio)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}.build()
Image Capture API (Take Photo)
fun onClick() {
val file = File(...)
imageCapture.takePicture(file,
object : ImageCapture.OnImageSavedListener {
override fun onError(error: ImageCapture.UseCaseError,
message: String, exc: Throwable?) {
// insert your code here.
}
override fun onImageSaved(file: File) {
// insert your code here.
}
Add in project
Add in build.gradle
dependencies {
// CameraX core library.
def camerax_version = "1.0.0-alpha03"
implementation "androidx.camera:camera-core:${camerax_version}"
// If you want to use Camera2 extensions.
implementation "androidx.camera:camera-camera2:${camerax_version}"
}
CameraX Extensions
CameraX Extensions
Supported Devices
● Huawei (HDR, Portrait): Mate 20 series, P30 series, Honor Magic 2, Honor View 20
● Samsung (HDR, Night, Beauty): Galaxy S10 series
Adding CameraX Extensions
- Apply extensions to CameraX Use cases
- Available extensions are Bokeh, Night, HDR and Beauty Mode
Implement Extension for Preview Use Case
Implement Extension for Preview Use Case 1/2
// Create a Builder same as in normal workflow.
PreviewConfig.Builder builder = new PreviewConfig.Builder();
// Create a Extender object which can be used to apply extension configurations.
BeautyPreviewExtender extender = BeautyPreviewExtender.create(builder);
if (extender.isExtensionAvailable()) {
extender.enableExtension();
}
Implement Extension for Preview Use Case 2/2
// Finish constructing configuration with the same flow as when not using extensions.
mPreview = new Preview(builder.build());
TextureView textureView = findViewById(R.id.textureView);
mPreview.setOnPreviewOutputUpdateListener(
new Preview.OnPreviewOutputUpdateListener() {
@Override
public void onUpdated(Preview.PreviewOutput output) {
textureView.setSurfaceTexture(output.getSurfaceTexture());
}
});
// bind use case
CameraX.bindToLifecycle(this, mPreview)
Implement Extension for ImageCapture Use Case
val builder = ImageCaptureConfig.Builder()
// Create a Extender object which can be used to apply extension configurations.
val bokehImageCapture = BokehImageCaptureExtender.create(builder)
// Query if extension is available (optional).
if (bokehImageCapture.isExtensionAvailable()) {
bokehImageCapture.enableExtension()
}
// Finish constructing configuration with the same flow as when not using extensions.
val config = builder.build()
val useCase = ImageCapture(config)
CameraX.bindToLifecycle(this as LifecycleOwner, useCase)
How to test CameraX Extensions
○ Download AndroidX source code using below link
https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/README.md
○ Open androidx-master-dev/frameworks/support in Android Studio.
○ Select camera-testapp-extensions and install on device
○ Test APK :
https://drive.google.com/open?id=1WR-ncfdojn6brNGVZqJlZkwdqE1KTUOf
Apps using CameraX
Camera360
Snow (S10+ plus)
CameraX resources
Code Lab : https://codelabs.developers.google.com/codelabs/camerax-getting-started/#2
Sample App : https://github.com/android/camera/tree/master/CameraXBasic
Training : https://developer.android.com/training/camerax
CameraX Presentation Slides : https://speakerdeck.com/calren/getting-started-with-camerax
Thank You

More Related Content

PDF
What’s new in Android JetPack
PDF
Improving app performance with Kotlin Coroutines
PDF
Building Modern Apps using Android Architecture Components
PDF
Building an app with Google's new suites
PDF
Jetpack, with new features in 2021 GDG Georgetown IO Extended
PDF
Sharper Better Faster Dagger ‡ - Droidcon SF
PDF
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
PDF
A gently introduction to AngularJS
What’s new in Android JetPack
Improving app performance with Kotlin Coroutines
Building Modern Apps using Android Architecture Components
Building an app with Google's new suites
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Sharper Better Faster Dagger ‡ - Droidcon SF
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
A gently introduction to AngularJS

What's hot (20)

PDF
A friend in need - A JS indeed
PPTX
Angular modules in depth
PDF
Building maintainable app
PPTX
Angular2 + rxjs
PPTX
Angular Workshop_Sarajevo2
PDF
Workshop 26: React Native - The Native Side
PDF
Using hilt in a modularized project
PPTX
React native by example by Vadim Ruban
PDF
AngularJS Project Setup step-by- step guide - RapidValue Solutions
PPTX
Dagger 2. The Right Way to Dependency Injections
PDF
Dagger 2. Right way to do Dependency Injection
PDF
AngularJS - TechTalk 3/2/2014
PDF
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
PDF
Workshop 25: React Native - Components
PDF
Modular Test-driven SPAs with Spring and AngularJS
PDF
Workshop 15: Ionic framework
PDF
PROMAND 2014 project structure
PDF
AngularJS - dependency injection
PPTX
Working with AngularJS
PDF
Rohit android lab projects in suresh gyan vihar
A friend in need - A JS indeed
Angular modules in depth
Building maintainable app
Angular2 + rxjs
Angular Workshop_Sarajevo2
Workshop 26: React Native - The Native Side
Using hilt in a modularized project
React native by example by Vadim Ruban
AngularJS Project Setup step-by- step guide - RapidValue Solutions
Dagger 2. The Right Way to Dependency Injections
Dagger 2. Right way to do Dependency Injection
AngularJS - TechTalk 3/2/2014
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Workshop 25: React Native - Components
Modular Test-driven SPAs with Spring and AngularJS
Workshop 15: Ionic framework
PROMAND 2014 project structure
AngularJS - dependency injection
Working with AngularJS
Rohit android lab projects in suresh gyan vihar
Ad

Similar to Exploring CameraX from JetPack (20)

PPTX
Android Camera Presentation on Benifits and disadvantages
PDF
CameraX, MLKit and AutoML at DevFest Songdo 2019
PDF
CameraX, MLKit and AutoML at DevFest Cebu 2019
PDF
camera_x_beyond_alpha
PDF
CameraX: Make photography easier on Android!
PDF
Camera2 API: Overview
PDF
Droidcon NYC 2014: Building Custom Camera Applications
PDF
Droidcon NYC 2014: Building Custom Camera Applications
PPTX
What's new in Android, Igor Malytsky ( Google Post I|O Tour)
PPTX
Android 5.0 Camera2 APIs
PPTX
Camera 2.0 in Android 4.2
PDF
Android camera2
PPTX
How to create a camera2
PDF
AnDevCon 2014: Building a Custom Camera Application
PDF
Building a Custom Camera Application in Android
DOCX
PPTX
Hidden Camera 3 APIs in Android 4.4 (KitKat)
PDF
Android Camera
PDF
Camera2 API, SHIM, and HAL 3.2 in Android 5.1
PDF
"Recent Developments in Khronos Standards for Embedded Vision," a Presentatio...
Android Camera Presentation on Benifits and disadvantages
CameraX, MLKit and AutoML at DevFest Songdo 2019
CameraX, MLKit and AutoML at DevFest Cebu 2019
camera_x_beyond_alpha
CameraX: Make photography easier on Android!
Camera2 API: Overview
Droidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera Applications
What's new in Android, Igor Malytsky ( Google Post I|O Tour)
Android 5.0 Camera2 APIs
Camera 2.0 in Android 4.2
Android camera2
How to create a camera2
AnDevCon 2014: Building a Custom Camera Application
Building a Custom Camera Application in Android
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Android Camera
Camera2 API, SHIM, and HAL 3.2 in Android 5.1
"Recent Developments in Khronos Standards for Embedded Vision," a Presentatio...
Ad

More from Hassan Abid (15)

PDF
[IO Extended KL] On-Device AI: Is It Time to Go All-In, or Do We Still Need t...
PDF
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
PDF
DevFest SG 2024 - What’s new in On-device Generative AI
PDF
What’s new in Android: Embracing era of Generative AI
PDF
Android 101 - Kotlin ( Future of Android Development)
PDF
Kotlin for Android Developers
PDF
Recap of Android Dev Summit 2018
PDF
What's new in Android Pie
PDF
Android Jetpack - Google IO Extended Singapore 2018
PDF
Django for mobile applications
PDF
VR Video Apps on Daydream
PDF
Best Practices in Media Playback
PDF
ExoPlayer for Application developers
PPTX
Android n preview
PDF
Introduction to Pakistan
[IO Extended KL] On-Device AI: Is It Time to Go All-In, or Do We Still Need t...
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
DevFest SG 2024 - What’s new in On-device Generative AI
What’s new in Android: Embracing era of Generative AI
Android 101 - Kotlin ( Future of Android Development)
Kotlin for Android Developers
Recap of Android Dev Summit 2018
What's new in Android Pie
Android Jetpack - Google IO Extended Singapore 2018
Django for mobile applications
VR Video Apps on Daydream
Best Practices in Media Playback
ExoPlayer for Application developers
Android n preview
Introduction to Pakistan

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
System and Network Administration Chapter 2
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Introduction to Artificial Intelligence
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
top salesforce developer skills in 2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administraation Chapter 3
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
medical staffing services at VALiNTRY
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
ai tools demonstartion for schools and inter college
AI in Product Development-omnex systems
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
System and Network Administration Chapter 2
CHAPTER 2 - PM Management and IT Context
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Introduction to Artificial Intelligence
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
top salesforce developer skills in 2025.pdf
Digital Strategies for Manufacturing Companies
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administraation Chapter 3
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
medical staffing services at VALiNTRY
Operating system designcfffgfgggggggvggggggggg
Odoo POS Development Services by CandidRoot Solutions
ai tools demonstartion for schools and inter college

Exploring CameraX from JetPack

  • 1. CameraX JetPack Android Developers day Jakarta 2019 Hassan Abid, GDE Android Twitter, Instagram, Github : @hassanabidpk
  • 2. What’s new in JetPack Library - Alpha - CameraX - LiveData and LifeCycle w/ coroutines - Benchmark - Security - ViewModel with SavedState - ViewPager2 - Beta - ConstraintLayout 2.0 - BioMetric Prompts - Stable - JetPack Compose - WorkManager - Navigation
  • 4. Introduction - Backward compatible with L+ devices - Consistent behavior across devices - Easy to use APIs - Based on Camera2 Apis but hides Hardware layer - Using CameraX results 70% fewer lines of code vs Camera2
  • 5. Issues tackled - Front/back camera switch crashes - Optimized camera closures - Incorrect Orientation - Flash not firing
  • 6. CameraX API (alpha) - Preview - Image Analysis - Image Capture
  • 7. Deep dive into CameraX
  • 9. Preview API val previewConfig = PreviewConfig.Builder().build()
  • 10. Preview API val previewConfig = PreviewConfig.Builder().build() val preview = Preview(previewConfig)
  • 11. Preview API val previewConfig = PreviewConfig.Builder().build() val preview = Preview(previewConfig) val textureView: TextureView = findViewById(R.id.textureView)
  • 12. Preview API val previewConfig = PreviewConfig.Builder().build() val preview = Preview(previewConfig) val textureView: TextureView = findViewById(R.id.textureView) // The output data-handling is configured in a listener. preview.setOnPreviewOutputUpdateListener { previewOutput -> textureView.surfaceTexture = previewOutput.surfaceTexture }
  • 13. Preview API val previewConfig = PreviewConfig.Builder().build() val preview = Preview(previewConfig) val textureView: TextureView = findViewById(R.id.textureView) // The output data-handling is configured in a listener. preview.setOnPreviewOutputUpdateListener { previewOutput -> textureView.surfaceTexture = previewOutput.surfaceTexture } // The use case is bound to an Android Lifecycle with the following code. CameraX.bindToLifecycle(this as LifecycleOwner, preview)
  • 15. CameraX Lifecycles - CameraX observes a lifecycle to determine camera states - When to open and close session
  • 17. Image Analysis API val imageAnalysisConfig = ImageAnalysisConfig.Builder() .setTargetResolution(Size(1280, 720)) .build()
  • 18. Image Analysis API val imageAnalysisConfig = ImageAnalysisConfig.Builder() .setTargetResolution(Size(1280, 720)) .build() val imageAnalysis = ImageAnalysis(imageAnalysisConfig)
  • 19. Image Analysis API val imageAnalysisConfig = ImageAnalysisConfig.Builder() .setTargetResolution(Size(1280, 720)) .build() val imageAnalysis = ImageAnalysis(imageAnalysisConfig) imageAnalysis.setAnalyzer({ image: ImageProxy, rotationDegrees: Int -> // insert your code here. })
  • 20. Image Analysis API val imageAnalysisConfig = ImageAnalysisConfig.Builder() .setTargetResolution(Size(1280, 720)) .build() val imageAnalysis = ImageAnalysis(imageAnalysisConfig) imageAnalysis.setAnalyzer({ image: ImageProxy, rotationDegrees: Int -> // insert your code here. }) CameraX.bindToLifecycle(this as LifecycleOwner, imageAnalysis, preview)
  • 22. Image Capture API (Simplified) val imageCaptureConfig = ImageCaptureConfig.Builder() .setTargetRotation(windowManager.defaultDisplay.rotation) .build() val imageCapture = ImageCapture(imageCaptureConfig) CameraX.bindToLifecycle(this as LifecycleOwner, imageCapture, imageAnalysis, preview)
  • 23. Image Capture API (Advance) val imageCaptureConfig = ImageCaptureConfig.Builder().apply { setLensFacing(lensFacing) setCaptureMode(CaptureMode.MIN_LATENCY) // We request aspect ratio but no resolution to match preview config but letting // CameraX optimize for whatever specific resolution best fits requested capture mode setTargetAspectRatio(screenAspectRatio) // Set initial target rotation, we will have to call this again if rotation changes // during the lifecycle of this use case setTargetRotation(viewFinder.display.rotation) }.build()
  • 24. Image Capture API (Take Photo) fun onClick() { val file = File(...) imageCapture.takePicture(file, object : ImageCapture.OnImageSavedListener { override fun onError(error: ImageCapture.UseCaseError, message: String, exc: Throwable?) { // insert your code here. } override fun onImageSaved(file: File) { // insert your code here. }
  • 26. Add in build.gradle dependencies { // CameraX core library. def camerax_version = "1.0.0-alpha03" implementation "androidx.camera:camera-core:${camerax_version}" // If you want to use Camera2 extensions. implementation "androidx.camera:camera-camera2:${camerax_version}" }
  • 29. Supported Devices ● Huawei (HDR, Portrait): Mate 20 series, P30 series, Honor Magic 2, Honor View 20 ● Samsung (HDR, Night, Beauty): Galaxy S10 series
  • 30. Adding CameraX Extensions - Apply extensions to CameraX Use cases - Available extensions are Bokeh, Night, HDR and Beauty Mode
  • 31. Implement Extension for Preview Use Case
  • 32. Implement Extension for Preview Use Case 1/2 // Create a Builder same as in normal workflow. PreviewConfig.Builder builder = new PreviewConfig.Builder(); // Create a Extender object which can be used to apply extension configurations. BeautyPreviewExtender extender = BeautyPreviewExtender.create(builder); if (extender.isExtensionAvailable()) { extender.enableExtension(); }
  • 33. Implement Extension for Preview Use Case 2/2 // Finish constructing configuration with the same flow as when not using extensions. mPreview = new Preview(builder.build()); TextureView textureView = findViewById(R.id.textureView); mPreview.setOnPreviewOutputUpdateListener( new Preview.OnPreviewOutputUpdateListener() { @Override public void onUpdated(Preview.PreviewOutput output) { textureView.setSurfaceTexture(output.getSurfaceTexture()); } }); // bind use case CameraX.bindToLifecycle(this, mPreview)
  • 34. Implement Extension for ImageCapture Use Case val builder = ImageCaptureConfig.Builder() // Create a Extender object which can be used to apply extension configurations. val bokehImageCapture = BokehImageCaptureExtender.create(builder) // Query if extension is available (optional). if (bokehImageCapture.isExtensionAvailable()) { bokehImageCapture.enableExtension() } // Finish constructing configuration with the same flow as when not using extensions. val config = builder.build() val useCase = ImageCapture(config) CameraX.bindToLifecycle(this as LifecycleOwner, useCase)
  • 35. How to test CameraX Extensions ○ Download AndroidX source code using below link https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/README.md ○ Open androidx-master-dev/frameworks/support in Android Studio. ○ Select camera-testapp-extensions and install on device ○ Test APK : https://drive.google.com/open?id=1WR-ncfdojn6brNGVZqJlZkwdqE1KTUOf
  • 37. CameraX resources Code Lab : https://codelabs.developers.google.com/codelabs/camerax-getting-started/#2 Sample App : https://github.com/android/camera/tree/master/CameraXBasic Training : https://developer.android.com/training/camerax CameraX Presentation Slides : https://speakerdeck.com/calren/getting-started-with-camerax