Welcome back.
We created this image analyzer.
Now let's set up the image capture.
Scroll down here.
Don't worry about the red lines.
We're going to use the returning statement.
So this is just a missing the returning statement.
Image capture equals to image capture dot build set target rotation.
And instead of using surface dot rotation we're going to use the preview view preview view dot display
dot rotation.
Then we're going to use the build function.
Here we are assigning the image capture state variable for use throughout the app.
So here the image capture equals to image capture dot builder.
Image capture dot builder creates a builder for capturing still photos.
Set target rotation.
Sets the target rotation for the image capture use cases and build function builds the image capture
instance.
This is a professional way to configure a use case specifically for taking high quality still photos.
Target rotations ensures captured images have the correct orientation based on how the device is held
and the preview dot display.
Dot rotation automatically handles device rotation changes.
This is very important for setting up the camera to capture properly oriented photos that match what
the user sees in the preview.
Let's continue configuring our camera and under the camera capture and the image capture.
Sorry, we need to create the camera selector.
Val camera selector equals to camera selector.
Dot default back camera.
We are setting and using the back camera camera provider that we created before.
Dot and bind all this unbind all function Unbinds all previously bound use cases cleans up existing
camera sessions.
Then we need to bind to life cycle.
So camera provider dot bind to life cycle.
And we need to pass five parameters lifecycle, camera selector, image preview or image capture preview
and analyzer.
Here we need to switch the is because lifecycle camera selector.
If we go to the bind here we have lifecycle owner.
That's the first variable.
The first variable is uh is the lifecycle owner ties the camera to component lifecycle automatically
starts and stop camera selector chooses which camera front or back The image capture, preview and analyzer.
The use cases to bind.
This is a clean setup and binds all sessions before starting new ones.
Camera automatically poses resumes with life cycle, so I'm attaching it to the life cycle.
Multiple use cases like image capture, preview and image analysis binds preview, capture and analysis
together so they work simultaneously.
This is a camera start up when life cycle becomes active, all bound use cases receive camera frames.
Camera stops when life cycle is destroyed because it's attached to life cycle owner and no manual camera
resource management needed.
This is the standard pattern for setting up camera Ex with multiple functionalities.
But here I need to switch the preview with camera with the image capture, making it the third and the
fourth Parameter.
And here we need to close this.
And this is the listener.
And outside the listener we need to pass the executor as the second parameter.
And here we go okay.
Now let me set the preview equals to preview dot builder dot dot also and set the set it to surface
Provider.
You can set the surface provider like this or like this equals to preview view dot surface provider
okay.
Now what we need to return is the preview view okay.
What we've done here the Preview Builder build creates a preview use case with default settings.
Also immediately configures the preview after building it, and it's surface provider connects the preview
to the UI surface.
This creates the camera preview that shows what the camera sees.
Links the camera output to the preview view.
Typically a preview view composable XML and the service provider handles rendering camera frames onto
the display.
How it works camera frames are streamed to the preview view via the service provider.
Users see a live camera preview in the UI.
This is essential for camera apps so users can frame their shots.
The result is the camera feed becomes visible in your app's UI through the camera preview, and this
is the returning type of this function and the returning type of this Android view.
Okay, so congratulations guys.
We set it correctly the camera, and we used our variables in order to control the settings and make
sure that the camera runs perfectly.