PreviewView Not Updated After Calling SetLinearZoom

Nathan Sokalski 4,126 Reputation points
2023-02-27T20:47:36.7866667+00:00

I am trying to zoom in/out on PreviewView using SetLinearZoom. I do this using the following line of code:

this.pvPreview.Controller.SetLinearZoom(value);

pvPreview is my PreviewView, this.pvPreview.Controller has been set to a LifecycleCameraController, and value is a float from 0.0 to 1.0, but my PreviewView is not updated. Is there something else I need to do?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,649 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points Microsoft Vendor
    2023-02-28T02:53:18.94+00:00

    Hello,

    You need to get CameraControl, then you can set the SetLinearZoom.

    Firstly, you need to find the cameraProvider.BindToLifecycle, then get the CameraControl like following code.

    // Bind use cases to camera
    CameraControl = cameraProvider.BindToLifecycle(this, cameraSelector, preview, imageCapture, imageAnalyzer).CameraControl;
    

    In the end, you can setLinearZoom, for testing, I change the linearzoom in the button click event like following code.

    AndroidX.Camera.Core.ICameraControl  CameraControl;
            float zoomrate = 0.1f;
            private void Camera_Move_button_Click(object sender, System.EventArgs e)
            {
                zoomrate += 0.1f;
                CameraControl.SetLinearZoom(zoomrate);
            }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful