Xamarin camera resolution

I made my own camera app in Xamarin Visual Studio, it accepts very low resolution images, so I added this code snippet.

public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h)
        {
            _camera = Android.Hardware.Camera.Open();
            Android.Hardware.Camera.Parameters param = _camera.GetParameters();
            IList<Android.Hardware.Camera.Size> supportedSizes = param.SupportedPictureSizes;
            Android.Hardware.Camera.Size sizePicture = supportedSizes[0];
            param.SetPictureSize(sizePicture.Height, sizePicture.Width);
            _camera.SetParameters(param);

            var previewSize = _camera.GetParameters().PreviewSize;
            _textureView.LayoutParameters = 
                new FrameLayout.LayoutParams(h, w, GravityFlags.Center);
            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            _textureView.Rotation = 90.0f;
        }

      

In the firts line, I get the camera parameters, after which I get the supported image size after that, I select firts ([0]), and eventually I set the image size,

Android.Hardware.Camera.Parameters param = _camera.GetParameters();
            IList<Android.Hardware.Camera.Size> supportedSizes = param.SupportedPictureSizes;
            Android.Hardware.Camera.Size sizePicture = supportedSizes[0];
            param.SetPictureSize(sizePicture.Height, sizePicture.Width);
            _camera.SetParameters(param);

      

But when I run the code this message appears:

Unhandled Exception:

Java.Lang.RuntimeException: setParameters failed

what is wrong here? I cannot set any supported size returned by the function? how to choose any of them, for example the first one? is there something else I should consider?

+3


source to share


1 answer


You have parameters width

and height

transposed in such a way that you end up with an invalid (unsupported) image size.

param.SetPictureSize(sizePicture.Width, sizePicture.Height);

      



void setPictureSize (int width, int height)

re: https://developer.android.com/reference/android/hardware/Camera.Parameters.html

+3


source







All Articles