I useing Camera2basic.
I have a Button ("Zoom") in MyApp.
I want to when I click on Zoom Button or when scale finger on screen set camera zoom value, but I dont have any idea how to do it.

sorry I cant speak English very well.
I useing Camera2basic.
I have a Button ("Zoom") in MyApp.
I want to when I click on Zoom Button or when scale finger on screen set camera zoom value, but I dont have any idea how to do it.

sorry I cant speak English very well.
I want to when I click on Zoom Button or when scale finger on screen set camera zoom value, but I dont have any idea how to do it
Hi, hosseintavakoli. Try to get the maxZoom and setZoom with the target CaptureRequest.Builder. Then send the new zoom to the current CameraCaptureSession with a Repeating Request to make it active.
Similar issue cases you could refer to:
https://stackoverflow.com/questions/52568987/camera-zoom-setting-using-camera2-api
https://stackoverflow.com/questions/35968315/android-camera2-handle-zoom
I checked above link but I don't understand how can I do it?
could you give me some code please?
Here is related code about the function, please check it.
var manager = Android.App.Application.Context.GetSystemService(Context.CameraService) as CameraManager;
var id_list = manager.GetCameraIdList();
var characteristics = manager.GetCameraCharacteristics(id_list[0]);
float maxZoom;
Rect mSensorSize = (Rect)characteristics.Get(CameraCharacteristics.SensorInfoActiveArraySize);
if (mSensorSize == null)
{
maxZoom = 1.0f;
return;
}
Rect mCropRegion = new Rect();
float zoom = 1.5f;
var newZoom = MathUtils.Clamp(zoom, 1.0f, 6.0f);
int centerX = mSensorSize.Width() / 2;
int centerY = mSensorSize.Height() / 2;
int deltaX = (int)((0.5f * mSensorSize.Width()) / newZoom);
int deltaY = (int)((0.5f * mSensorSize.Height()) / newZoom);
mCropRegion.Set(centerX - deltaX,
centerY - deltaY,
centerX + deltaX,
centerY + deltaY);
mPreviewRequestBuilder.Set(CaptureRequest.ScalerCropRegion, mCropRegion);
mCaptureSession.SetRepeatingRequest(mPreviewRequestBuilder.Build(), null, null);//you could define the callback and handler
Tnx a lot zoom is working, but when I click on TakePicture Button can't take picture.
Hi, did you change some other code? The above code shouldn't affect the 'TakePicture' function and it works fine on my side.
No I didn't change code just Copy & Paste. when I click on take_picture button it will try to focus but doesn't take picture.
I didn't change code just Copy & Paste. when I click on take_picture button it will try to focus but doesn't take picture.
Sorry, I cannot reproduce the issue on my side. Would you mind sharing a basic on github or onedrive and then post the link here? It'll help to get the cause to the issue.
When I click on Zoom button zoom work correctly , but after zoom when I click on TakePicture Button It cant take photo with zoom.
Please add a breakpoint to debug the 'TakePicture' method to check which line code caused the problem.
Zoom and Taking photo worked correctly now. but there is a problem when I taking photo with zoom after click on TakePhoto button picture saved without zoom and camera view going out of zoom.
I checked on some devices and problem still yet.

Please change the parameters of the captureBuilder.Set command in CaptureStillPicture method.
Rect mCropRegion = null;
private void ZoomButton_Click(object sender, EventArgs e)
{
...
mCropRegion = new Rect();
...
}
public void CaptureStillPicture()
{
try
{
...
if (mCropRegion != null)
{
stillCaptureBuilder.Set(CaptureRequest.ScalerCropRegion, mCropRegion);
mCropRegion = null;
}
else
{
stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
}
...
}
catch (CameraAccessException e)
{
e.PrintStackTrace();
}
}
Check the link: https://stackoverflow.com/questions/35968315/android-camera2-handle-zoom
5 people are following this question.