now am implementing zoomin and zoomout when before taking picture its not working properly, But its not working properly? Is there any example? I call that function when device recognize pinch gesture. Thank you in advance.
public override bool OnTouchEvent(MotionEvent e)
{
global::Android.Hardware.Camera.Parameters parameters = camera.GetParameters();
maximumZoomLevel = (float)cameraCharacteristics?.Get(CameraCharacteristics.ScalerAvailableMaxDigitalZoom);
Android.Graphics.Rect rect = (Android.Graphics.Rect)cameraCharacteristics?.Get(CameraCharacteristics.SensorInfoActiveArraySize);
if (rect == null) return false;
float currentFingerSpacing;
if (e.PointerCount == 2)
{
currentFingerSpacing = getFingerSpacing(e);
float delta = 0.05f;
if (fingerSpacing != 0)
{
if (currentFingerSpacing > fingerSpacing)
{ //Don't over zoom-in
if ((maximumZoomLevel - zoomLevel) <= delta)
{
delta = maximumZoomLevel - zoomLevel;
}
zoomLevel = zoomLevel + delta;
}
else if (currentFingerSpacing < fingerSpacing)
{ //Don't over zoom-out
if ((zoomLevel - delta) < 1f)
{
delta = zoomLevel - 1f;
}
zoomLevel = zoomLevel - delta;
}
float ratio = (float)1 / zoomLevel;
int croppedWidth = (int)(rect.Width() - Math.Round((float)rect.Width() * ratio));
int croppedHeight = (int)(rect.Height() - Math.Round((float)rect.Height() * ratio));
//Finally, zoom represents the zoomed visible area
zoom = new Android.Graphics.Rect(croppedWidth / 2, croppedHeight / 2,
rect.Width() - croppedWidth / 2, rect.Height() - croppedHeight / 2);
previewRequestBuilder.Set(CaptureRequest.ScalerCropRegion, zoom);
}
fingerSpacing = currentFingerSpacing;
captureSession.SetRepeatingRequest(previewRequestBuilder.Build(), CaptureCallBack, null);
}
return true;
}