private Camera.Parameters GetModifiedParameters(Camera.Parameters oldParameters)
        {
            Camera.Parameters newParameters = oldParameters;
            Camera.Size       size          = FindMaxSize(newParameters.SupportedPictureSizes);

            newParameters.SetPreviewSize(640, 480);
            newParameters.SetPictureSize(size.Width, size.Height);
            newParameters.Set("contrast", "0");
            newParameters.FlashMode = Camera.Parameters.FlashModeOff;
            newParameters.FocusMode = Camera.Parameters.FocusModeAuto;
            newParameters.SceneMode = Camera.Parameters.SceneModeAuto;
            //newParameters.AutoExposureLock = false;
            newParameters.WhiteBalance = Camera.Parameters.WhiteBalanceAuto;
            //newParameters.ExposureCompensation = -12;
            newParameters.PictureFormat = Android.Graphics.ImageFormat.Jpeg;
            newParameters.JpegQuality   = 100;
            int angle = _cameraInfo.CalculateRotationAngle(CAMERA_ID);

            newParameters.SetRotation(angle);

            return(newParameters);
        }
Ejemplo n.º 2
0
        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            if (!changed)
            {
                return;
            }

            int width         = right - left;
            int height        = bottom - top;
            int previewWidth  = width;
            int previewHeight = height;

            if (previewSize != null)
            {
                Display display = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>().DefaultDisplay;

                switch (display.Rotation)
                {
                case SurfaceOrientation.Rotation0:
                    previewWidth  = previewSize.Height;
                    previewHeight = previewSize.Width;
                    break;

                case SurfaceOrientation.Rotation90:
                    previewWidth  = previewSize.Width;
                    previewHeight = previewSize.Height;
                    break;

                case SurfaceOrientation.Rotation180:
                    previewWidth  = previewSize.Height;
                    previewHeight = previewSize.Width;
                    break;

                case SurfaceOrientation.Rotation270:
                    previewWidth  = previewSize.Width;
                    previewHeight = previewSize.Height;
                    break;
                }
            }

            int scaledChildHeight = previewHeight * width / previewWidth;

            cameraView.Layout(0, height - scaledChildHeight, width, height);

            Camera.Parameters camParams = Camera.GetParameters();

            if (base.Resources.Configuration.Orientation == global::Android.Content.Res.Orientation.Landscape)
            {
                camParams.Set("orientation", "landscape");
                camParams.SetRotation(0);
                Camera.SetDisplayOrientation(0);
            }
            else
            {
                camParams.Set("orientation", "portrait");
                camParams.SetRotation(90);
                Camera.SetDisplayOrientation(90);
            }

            if (isVideo && camParams.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousVideo))
            {
                camParams.FocusMode = Camera.Parameters.FocusModeContinuousVideo;
            }
            else if (!isVideo && camParams.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
            {
                camParams.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
            }
            else if (camParams.SupportedFocusModes.Contains(Camera.Parameters.FocusModeAuto))
            {
                camParams.FocusMode = Camera.Parameters.FocusModeAuto;
            }

            Camera.SetParameters(camParams);
        }