Reputation: 17
I am currently working on an Android application using the standard Java and XML approach. My app uses the Camera2 API to adjust ISO, shutter speed, and auto white balance (AWB). I am planning to switch to Jetpack Compose for its modern and declarative UI framework.
I would like to know how to integrate the Camera2 API with Jetpack Compose to adjust camera settings like ISO, shutter speed, and AWB. Specifically, I'm looking for:
Setting up Camera2 API with Jetpack Compose: How to initialize and use Camera2 in a Compose environment. Adjusting Camera Parameters: How to programmatically adjust ISO, shutter speed, and AWB using Camera2 in Compose. UI Integration: Best practices for creating a UI in Compose that allows users to adjust these parameters. If anyone can provide an example or point me to relevant resources, I would greatly appreciate it.
Thank you in advance for your help!
I haven't implemented anything yet, but I have researched online. Most of the resources and tutorials I found lead to using CameraX. However, CameraX does not support manual parameter adjustments such as ISO, shutter speed, and AWB, which are essential for my application.
Upvotes: 1
Views: 295
Reputation: 1275
Just had the same problem and found the solution in this post.
So in my case, I replaced
Preview preview = new Preview.Builder().build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
with the following snippet
Preview.Builder previewBuilder = new Preview.Builder();
var ext1 = new Camera2Interop.Extender(previewBuilder)
.setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)
.setCaptureRequestOption(CaptureRequest.SENSOR_EXPOSURE_TIME, 244141L)
.setCaptureRequestOption(CaptureRequest.SENSOR_SENSITIVITY, 800);
Preview preview = previewBuilder.build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
Upvotes: 0
Reputation: 18097
At the most basic, you could just use your existing preview View (SurfaceView? TextureView?) wrapped into a Compose AndroidView.
You could also consider using CameraX's CameraViewfinder which is compatible with camera2 as well, and simplifies a lot of the irritations of managing aspect ratios, compatibility between TextureView and SurfaceView, and so on.
There's no direct Compose compat story for CameraViewfinder
yet, but that's something that may well appear. At which point it'd be simple to adapt to those changes.
Upvotes: 0