Camera Using custom Camera Preview Renderer is not

2019-07-31 16:07发布

问题:

I am using the following link to display the camera preview using Custom renderers https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/view/

I was able to bring up the camera preview. But the preview is not at all clear. There is no Auto focus as well. Screenshot for reference

How can I make the camera preview clearer, because I wish to use the same later on for OCR.

Thanks,

回答1:

I think you already figured this out but I'm going to post the solution here for reference.

You need to setup the "Focus Mode" in the Camera properties.

Camera Preview = Camera.Open(1);
// Set the parameters.
if (Preview != null)
{
    Camera.Parameters cameraParameters = Preview.GetParameters();
    // Autofocus
    cameraParameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
    // Set
    cameraPreview.Preview.SetParameters(cameraParameters);
}

For the example you mentioned (the one in https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/view/) you should place this code in you Android Cutom Renderer (CameraPreviewRenderer method OnElementChanged).

It worked for me. Hope this helps.