Search code examples
androidmauiandroid-camera2

MAUI - Android Camera2 - How set Rotate and Crop in CaptureRequest


I am trying to set the crop rect and the rotation for a capture request of the Android.Camera2.CameraDevice. The CaptureRequest.Builder has a Set function where I can set the values for multiple keys.

But when I try to do something like:

builder.Set(CaptureRequest.ScalerRotateAndCrop180, null);

I get the message that this way is obsolete and that I should use the ScalerRotateAndCropType directly.

I can also do something like

builder.Set(CaptureRequest.ScalerRotateAndCrop, null);

This seems to be ok, but the rotation is missing.

So how do I use these functions correctly?


Solution

  • Note that most devices do not support this control; generally only a few foldable devices do currently.

    You can check if it's supported via https://learn.microsoft.com/en-us/dotnet/api/android.hardware.camera2.cameracharacteristics.scaleravailablerotateandcropmodes?view=net-android-34.0 . Most likely, only ROTATE_AND_CROP_NONE will be supported on your device.

    Therefore, if you need to rotate the image for your application, you'll need to do that yourself or find an image processing library to do it for you.