I try to change the aspect ratio of the Camera2 preview but I fail :-(
For cropping I have to use the SCALER_CROP_REGION but I don't get it working.
I used the android-Camera2Video example from Google for my tests.
In the openCamera method I added the following line:
mSensorSize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
And in startPreview I added this:
final int centerX = mSensorSize.width() / 2;
final int centerY = mSensorSize.height() / 2;
final int cropSize = Math.min(mSensorSize.width(), mSensorSize.height());
final Rect crop = new Rect(centerY - cropSize / 2,
centerX - cropSize / 2,
cropSize,
cropSize);
mPreviewBuilder.set(CaptureRequest.SCALER_CROP_REGION, crop);
I should get a preview with a 1:1 ratio but it is 3:4 :-(
What did I wrong?
you may try to change
onMeasure
method inside your AutofitTextureView classthis is before applying above method
and this is after applying above method
Camera2Video google sample
and i also removed thse two lines in the
fragment_camera2_video.xml
I am calling setAspectRation from my camera Fragment as follows