当前位置: 首页>>代码示例>>C#>>正文


C# Camera.StartPreview方法代码示例

本文整理汇总了C#中Android.Hardware.Camera.StartPreview方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.StartPreview方法的具体用法?C# Camera.StartPreview怎么用?C# Camera.StartPreview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Hardware.Camera的用法示例。


在下文中一共展示了Camera.StartPreview方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartPreview

        protected sealed override void StartPreview()
        {
            _camera = Camera.Open((int)CurrentCamera);
            _camera.SetDisplayOrientation(90);

            var parameters = _camera.GetParameters();
            if (parameters.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
            {
                parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
            }

            var optimalSize = GetOptimalPreviewSize(_width, _height);
            if (optimalSize != null)
            {
                parameters.SetPreviewSize(optimalSize.Width, optimalSize.Height);
            }

            _camera.SetParameters(parameters);

            try
            {
                _camera.SetPreviewTexture(_surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:willsb,项目名称:PhotoCaptureView,代码行数:29,代码来源:CameraController.cs

示例2: OnSurfaceTextureAvailable

 public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int w, int h)
 {
     _camera = Camera.Open ();
     
     _textureView.LayoutParameters = new FrameLayout.LayoutParams (w, h);
     
     try {
         _camera.SetPreviewTexture (surface);
         _camera.StartPreview ();
         
     } catch (Java.IO.IOException ex) {
         Console.WriteLine (ex.Message);
     }
 }
开发者ID:eduardoguilarducci,项目名称:recipes,代码行数:14,代码来源:Activity1.cs

示例3: Liga

        public bool Liga()
        {
            if (TemFlash)
            {
                camera = Camera.Open();

                var parametros = camera.GetParameters();
                parametros.FlashMode = Camera.Parameters.FlashModeTorch;

                camera.SetParameters(parametros);
                camera.StartPreview();

                return true;
            }
            return false;
        }
开发者ID:RonildoSouza,项目名称:HajaLuz,代码行数:16,代码来源:Flash.cs

示例4: OnSurfaceTextureAvailable

        public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int width, int height)
        {
            // var camInfo = new Camera.CameraInfo();

                    _camera = Camera.Open(0);

               // _camera = Camera.Open();
            _textureView.LayoutParameters = new FrameLayout.LayoutParams(width, height);
            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:JRolandros,项目名称:PluginTest,代码行数:18,代码来源:CameraPage.cs

示例5: OnSurfaceTextureAvailable

 public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int width, int height)
 {
     _camera = Camera.Open ();
     
     var previewSize = _camera.GetParameters ().PreviewSize;
     _textureView.LayoutParameters = 
         new FrameLayout.LayoutParams (previewSize.Width, previewSize.Height, (int)GravityFlags.Center);
     
     try {
         _camera.SetPreviewTexture (surface);
         _camera.StartPreview ();
     } catch (Java.IO.IOException ex) {
         Console.WriteLine (ex.Message);
     }
     
     // this is the sort of thing TextureView enables
     _textureView.Rotation = 45.0f;
     _textureView.Alpha = 0.5f;
 }
开发者ID:GSerjo,项目名称:Seminars,代码行数:19,代码来源:TextureViewActivity.cs

示例6: OnSurfaceTextureAvailable

        public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int width, int height)
        {
            _camera = Camera.Open ();
            ConfigureCamera ();

            Preview preview = new Preview ();
            preview.OnFrame += OnPreviewFrame;
            _camera.SetPreviewCallback (preview);

            _textureView.LayoutParameters = new FrameLayout.LayoutParams (width, height);

            try {
                _camera.SetPreviewTexture (surface);
                _camera.StartPreview ();

            } catch (Exception e) {
                Console.WriteLine (e.Message);
            }
        }
开发者ID:hbons,项目名称:Invert,代码行数:19,代码来源:MainActivity.cs

示例7: OnOptionsItemSelected

        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            // Handle item selection
            switch (item.ItemId) {
            case Resource.Id.switch_cam:
                // Release this camera -> mCameraCurrentlyLocked
                if (mCamera != null) {
                    mCamera.StopPreview ();
                    mPreview.SetCamera (null);
                    mCamera.Release ();
                    mCamera = null;
                }

                // Acquire the next camera and request Preview to reconfigure
                // parameters.
                mCamera = Camera.Open ((mCameraCurrentlyLocked + 1) % mNumberOfCameras);
                mCameraCurrentlyLocked = (mCameraCurrentlyLocked + 1)
                    % mNumberOfCameras;
                mPreview.SwitchCamera (mCamera);

                // Start the preview
                mCamera.StartPreview();
                return true;
            case Android.Resource.Id.Home:
                Intent intent = new Intent (this.Activity, typeof (MainActivity));
                intent.AddFlags (ActivityFlags.ClearTop | ActivityFlags.SingleTop);
                StartActivity (intent);
                goto default;
            default:
                return base.OnOptionsItemSelected (item);
            }
        }
开发者ID:4ndr01d,项目名称:monodroid-samples,代码行数:32,代码来源:CameraFragment.cs

示例8: SurfaceChanged

        public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
        {
            //var parameters = camera.GetParameters();
            //parameters.SetPreviewSize(width, height);

            //IList<Android.Hardware.Camera.Size> vSizeList = parameters.SupportedPictureSizes;

            //for (int num = 0; num < vSizeList.Count; num++)

            //{

            //    var vSize = vSizeList[num];

            //}

            if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape)

            {
                camera.SetDisplayOrientation(90);
            }

            else

            {
                camera.SetDisplayOrientation(0);
            }

            //camera.SetParameters(parameters);
            try
            {
                camera.SetPreviewDisplay(holder);

            }
            catch (Exception exception)
            {
                camera.Release();
                camera = null;
            }
            camera.StartPreview();
            //�Զ��Խ�
            //camera.AutoFocus(this);
        }
开发者ID:wnf0000,项目名称:Wood,代码行数:42,代码来源:Camera.cs

示例9: CreateCamera

        /// <summary>
        /// Create the camera and try to set auto focus with flash
        /// </summary>
        /// <param name="holder"></param>
		public void CreateCamera(ISurfaceHolder holder) {
			try
			{
				_camera = Camera.Open();
				Camera.Parameters p = _camera.GetParameters();
				p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
				p.JpegQuality = 100;
				hasAutoFocus = (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeAuto));
				if (hasAutoFocus)
				{
					p.FocusMode = Camera.Parameters.FocusModeAuto;
					focusReady = true;
				}
				else if (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
				{
					p.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
				}
				if (p.SupportedFlashModes.Contains(Camera.Parameters.FlashModeOn))
				{
					p.FlashMode = Camera.Parameters.FlashModeOn;
				}
				_camera.SetParameters(p);
				_camera.SetDisplayOrientation(90);
				_camera.SetPreviewCallback(this);
				_camera.Lock();
				_camera.SetPreviewDisplay(holder);
				_camera.StartPreview();
				if (hasAutoFocus)
				{
					Toast.MakeText(this, "Press screen to focus", ToastLength.Long).Show();
				}
			}
			catch (Exception e)
			{
			}
		}
开发者ID:SansSkill,项目名称:Introproject,代码行数:40,代码来源:CameraActivity.cs

示例10: StartPreview

        private bool StartPreview(Camera camera)
        {
            if (camera == null) { return false; }

            StopPreview(camera);

            // Mark preview as started if surface holder not yet created. We will really start it later
            _previewStarted = true;
            if (_surfaceHolder == null) { return false; }

            camera.SetDisplayOrientation(_displayOrientation);
            camera.SetPreviewDisplay(_surfaceHolder);

            try { camera.StartPreview(); }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("StartPreview {0}", ex);
                return false;
            }

            return true;
        }
开发者ID:BenGladman,项目名称:Camdro,代码行数:22,代码来源:Viewfinder.cs

示例11: OnOptionsItemSelected

		public override bool OnOptionsItemSelected (IMenuItem item)
		{
			// Handle item selection
			switch (item.ItemId) {
			case Resource.Id.switch_cam:
				// check for availability of multiple cameras
				if (numberOfCameras == 1) {
					AlertDialog.Builder builder = new AlertDialog.Builder (this);
					builder.SetMessage (GetString (Resource.String.camera_alert))
						.SetNeutralButton ("Close", (Android.Content.IDialogInterfaceOnClickListener)null);
					AlertDialog alert = builder.Create ();
					alert.Show ();
					return true;
				}

				// OK, we have multiple cameras.
				// Release this camera -> cameraCurrentlyLocked
				if (mCamera != null) {
					mCamera.StopPreview ();
					mPreview.PreviewCamera = null;
					mCamera.Release ();
					mCamera = null;
				}

				// Acquire the next camera and request Preview to reconfigure
				// parameters.
				mCamera = Camera.Open ((cameraCurrentlyLocked + 1) % numberOfCameras);
				cameraCurrentlyLocked = (cameraCurrentlyLocked + 1) % numberOfCameras;
				mPreview.SwitchCamera (mCamera);

				// Start the preview
				mCamera.StartPreview ();
				return true;

			default:
				return base.OnOptionsItemSelected (item);
			}
		}
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:38,代码来源:CameraPreview.cs


注:本文中的Android.Hardware.Camera.StartPreview方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。