internal void DoFocus(Rect r) { var handler = new FocusCallback(this); //CANCEL PREVIOUS AUTOFOCUS previewSession.StopRepeating(); previewBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.Off); previewBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Cancel); previewSession.Capture(previewBuilder.Build(), handler, backgroundHandler); previewBuilder.Set(CaptureRequest.ControlMode, (int)ControlMode.Auto); previewBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.Auto); previewBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start); MeteringRectangle rect = new MeteringRectangle(r, MeteringRectangle.MeteringWeightMax); previewBuilder.SetTag("FOCUS"); previewBuilder.Set(CaptureRequest.ControlAfRegions, new MeteringRectangle[] { rect }); previewSession.Capture(previewBuilder.Build(), handler, backgroundHandler); }
public void ChangeFocusPoint(Xamarin.Forms.Point e) { string cameraId = _manager.GetCameraIdList()[0]; // To get a list of available sizes of camera preview, we retrieve an instance of // StreamConfigurationMap from CameraCharacteristics CameraCharacteristics characteristics = _manager.GetCameraCharacteristics(cameraId); var rect = characteristics.Get(CameraCharacteristics.SensorInfoActiveArraySize) as Rect; var size = characteristics.Get(CameraCharacteristics.SensorInfoPixelArraySize) as Size; int areaSize = 200; int right = rect.Right; int bottom = rect.Bottom; int viewWidth = _cameraTexture.Width; int viewHeight = _cameraTexture.Height; int ll, rr; Rect newRect; int centerX = (int)e.X; int centerY = (int)e.Y; ll = ((centerX * right) - areaSize) / viewWidth; rr = ((centerY * bottom) - areaSize) / viewHeight; int focusLeft = Clamp(ll, 0, right); int focusBottom = Clamp(rr, 0, bottom); newRect = new Rect(focusLeft, focusBottom, focusLeft + areaSize, focusBottom + areaSize); MeteringRectangle meteringRectangle = new MeteringRectangle(newRect, 500); MeteringRectangle[] meteringRectangleArr = { meteringRectangle }; _previewBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Cancel); _previewBuilder.Set(CaptureRequest.ControlAeRegions, meteringRectangleArr); _previewBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start); UpdatePreview(); }