3

I have done a custom camera application in Xamarin Visual Studio, it takes the pictures with a very low resolution, so I added this piece of code.

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, then I get the Supported Picture Size after that I select the firts ([0]) and finallly I set the Picture 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 shows up:

Unhandled Exception:

Java.Lang.RuntimeException: setParameters failed

what is wrong here ? I can not set any of the supported sizes that the function returns ? how to I select any of them for instance the first? there is something else that I have to tke into account?

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
Nicole Ramírez
  • 345
  • 3
  • 19

1 Answers1

3

You have the width and height parameters transposed thus supplying an invalid (non-supported) picture size.

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

void setPictureSize (int width, int height)

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

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • could you help me wih this issue:http://stackoverflow.com/questions/43019874/xamarin-texture-view-camera-stream-size this is too much more dificult – Nicole Ramírez Mar 26 '17 at 20:13