Пример #1
0
        public async void Start()
        {
            if (idx == 0)
            {
                idx++;

                _camera = Camera.Open(1);
                var camParams = _camera.GetParameters();
                var fps       = camParams.SupportedPreviewFpsRange;
                camParams.SetPreviewSize(640, 480);
                camParams.SetPreviewFpsRange(fps[0][0], fps[0][1]);
                var supportedPictureFormats = camParams.SupportedPictureFormats;
                var previewFormat           = camParams.PreviewFormat;
                var supportedpreviewFormat  = camParams.SupportedPreviewFormats;
                foreach (var item in supportedpreviewFormat)
                {
                    Graph.ImageFormatType type = (Graph.ImageFormatType)item.IntValue();
                }
                _camera.SetParameters(camParams);
                _camera.SetPreviewTexture(_textureView);
                _camera.SetDisplayOrientation(90);
                _camera.SetPreviewCallback(new CameraPreviewCallback(this.nv21Sender));
                _camera.StartPreview();


                //if (CrossMedia.Current.IsTakePhotoSupported)
                //{
                //    await this.CheckPermissions();
                //    try
                //    {
                //        await CrossMedia.Current.Initialize();
                //        var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions()
                //        { DefaultCamera = CameraDevice.Front }
                //        );

                //    }
                //    catch (Exception e)
                //    {

                //    }
                //}
            }
        }
Пример #2
0
        protected override void OnStart()
        {
            try
            {
                if (Camera == null)
                {
                    Camera = Hardware.Camera.Open(cameraIndex);
                }

                if (Texture == null)
                {
                    Texture = new Graphics.SurfaceTexture(0);
                }

                CameraPreviewCallback callback = new CameraPreviewCallback();
                callback.PreviewUpdated += Callback_PreviewUpdated;

                Hardware.Camera.Parameters  parameter   = Camera.GetParameters();
                List <Hardware.Camera.Size> supportSize = parameter.SupportedPreviewSizes.OrderByDescending(x => x.Width).ToList();
                foreach (Hardware.Camera.Size size in supportSize)
                {
                    CvLogger.Log(this, $"Camera Support Size: W{size.Width},H{size.Height}");

                    if (size.Width == 960 && size.Height == 720)
                    {
                        parameter.SetPreviewSize(size.Width, size.Height);
                        CvLogger.Log(this, $"SET Camera Size: W{size.Width},H{size.Height}");
                    }
                }

                string[] supportedFocusMode = parameter.SupportedFocusModes.ToArray();
                if (supportedFocusMode.Contains(Hardware.Camera.Parameters.FocusModeContinuousVideo))
                {
                    parameter.FocusMode = Hardware.Camera.Parameters.FocusModeContinuousVideo;
                }
                else if (supportedFocusMode.Contains(Hardware.Camera.Parameters.FocusModeContinuousPicture))
                {
                    parameter.FocusMode = Hardware.Camera.Parameters.FocusModeContinuousPicture;
                }
                parameter.ColorEffect = Hardware.Camera.Parameters.EffectNone;

                width      = parameter.PreviewSize.Width;
                height     = parameter.PreviewSize.Height;
                fps        = parameter.PreviewFrameRate;
                cameraType = parameter.PreviewFormat;

                CvLogger.Log(this, string.Format("Camera is creating W{0} H{1} FPS{2}", width, height, fps));
                Camera.SetParameters(parameter);

                Camera.SetPreviewCallback(callback);
                Camera.SetPreviewTexture(Texture);
                Camera.StartPreview();

                cameraOn = true;
            }
            catch (Exception ex)
            {
                CvLogger.Log(this, "Camera Init Failed.\n" + ex.ToString());

                Dispose();

                throw new ArgumentException("Camera Exception", ex);
            }
        }