• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Hardware.Camera类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Camera类属于Android.Hardware命名空间,在下文中一共展示了Camera类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: StartPreview

 public void StartPreview()
 {
     try
     {
         var numberOfCameras = Camera.NumberOfCameras;
         int? rearFacingCameraId = null;
         // Find the ID of the default camera
         Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
         for (int i = 0; i < numberOfCameras; i++)
         {
             Camera.GetCameraInfo(i, cameraInfo);
             if (cameraInfo.Facing == CameraFacing.Back)
             {
                 rearFacingCameraId = i;
             }
         }
         if (rearFacingCameraId.HasValue)
         {
             camera = Camera.Open(rearFacingCameraId.Value);
             if (cameraPreview != null)
             {
                 cameraPreview.PreviewCamera = camera;
             }
         }
     }
     catch (CameraAccessException ex)
     {
     }
     catch (NullPointerException)
     {
     }
     catch (System.Exception ex)
     {
     }
 }
开发者ID:builttoroam,项目名称:BuildIt,代码行数:35,代码来源:CameraFeedUtility.cs


示例2: 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


示例3: TurnOff

      /// <summary>
      /// Turn the lamp off
      /// </summary>
      public void TurnOff()
      {
          if (camera == null)
              camera = Camera.Open();

          if (camera == null)
          {
              Debug.WriteLine("Camera failed to initialize");
              return;
          }

          var p = camera.GetParameters();
          var supportedFlashModes = p.SupportedFlashModes;

          if (supportedFlashModes == null)
              supportedFlashModes = new List<string>();

          var flashMode = string.Empty;

          if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeTorch))
              flashMode = Android.Hardware.Camera.Parameters.FlashModeOff;

          if (!string.IsNullOrEmpty(flashMode))
          {
              p.FlashMode = flashMode;
              camera.SetParameters(p);
          }
      }
开发者ID:dconlisk,项目名称:Xamarin.Plugins,代码行数:31,代码来源:LampImplementation.cs


示例4: OnCreateView

		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			// Open an instance of the first camera and retrieve its info.
			camera = GetCameraInstance (CAMERA_ID);
			Camera.CameraInfo cameraInfo = null;

			if (camera != null) {
				// Get camera info only if the camera is available
				cameraInfo = new Camera.CameraInfo ();
				Camera.GetCameraInfo (CAMERA_ID, cameraInfo);
			}

			if (camera == null || cameraInfo == null) {
				Toast.MakeText (Activity, "Camera is not available.", ToastLength.Short).Show ();
				return inflater.Inflate (Resource.Layout.fragment_camera_unavailable, null);
			}

			View root = inflater.Inflate (Resource.Layout.fragment_camera, null);

			// Get the rotation of the screen to adjust the preview image accordingly.
			SurfaceOrientation displayRotation = Activity.WindowManager.DefaultDisplay.Rotation;

			// Create the Preview view and set it as the content of this Activity.
			cameraPreview = new CameraPreview (Activity, camera, cameraInfo, displayRotation);
			var preview =  root.FindViewById <FrameLayout> (Resource.Id.camera_preview);
			preview.AddView (cameraPreview);

			return root;
		}
开发者ID:Appercode,项目名称:monodroid-samples,代码行数:29,代码来源:CameraPreviewFragment.cs


示例5: OnSurfaceTextureAvailable

        public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int width, int height)
        {
			if (Camera.NumberOfCameras == 0) {
				Toast.MakeText (this, Resource.String.no_camera, ToastLength.Long).Show ();
				return;
			}
			_camera = Camera.Open();
			if (_camera == null)
				_camera = Camera.Open (0);
            
            var previewSize = _camera.GetParameters ().PreviewSize;
            _textureView.LayoutParameters = 
                new FrameLayout.LayoutParams (previewSize.Width, previewSize.Height, 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:CHANDAN145,项目名称:monodroid-samples,代码行数:25,代码来源:TextureViewActivity.cs


示例6: OnCreate

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

			SetContentView(Resource.Layout.ScannerView);

            var frameLayout = (FrameLayout)FindViewById(Resource.Id.cameraPreview);

            camera = GetCameraInstance();

            if (camera == null)
            {
                Complete(new Intent());
                return;
            }

            previewCb = new PreviewCallback();

            previewCb.ScanComplete += PreviewCb_ScanComplete;

            camPreview = new CameraPreview(this, camera, previewCb);

            frameLayout.AddView(camPreview);
                
        }
开发者ID:joacar,项目名称:MonoDroid.ZBar,代码行数:25,代码来源:ScannerActivity.cs


示例7: OnPause

 public override void OnPause()
 {
     base.OnPause();
     if (mCamera != null) {
         mCamera.Release();
         mCamera = null;
     }
 }
开发者ID:yingfangdu,项目名称:BNR,代码行数:8,代码来源:CrimeCameraFragment.cs


示例8: StartCamera

		protected void StartCamera() {
			if (_Camera == null) {
				_Camera = Camera.Open();
				_CameraSupportedFlashModes = _CameraSupportedFlashModes ?? _Camera.GetParameters().SupportedFlashModes;
				if (_CameraSupportedFlashModes == null || !_CameraSupportedFlashModes.Contains(FlashlightOnMode) || !_CameraSupportedFlashModes.Contains(FlashlightOffMode)) {
					StopCamera();
				}
			}
		}
开发者ID:Vaikesh,项目名称:Flash-Torch_Xamarin.Android,代码行数:9,代码来源:FlashTorchActivity.cs


示例9: OnResume

		protected override void OnResume ()
		{
			base.OnResume ();

			// Open the default i.e. the first rear facing camera.
			mCamera = Camera.Open ();
			cameraCurrentlyLocked = defaultCameraId;
			mPreview.PreviewCamera = mCamera;
		}
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:9,代码来源:CameraPreview.cs


示例10: GetCameraFlashMode

 protected string GetCameraFlashMode(Camera.Parameters cameraParameters = null)
 {
     string mode = null;
     if (_Camera != null) {
         if (cameraParameters == null) {
             cameraParameters = _Camera.GetParameters();
         }
         mode = cameraParameters.FlashMode;
     }
     return mode;
 }
开发者ID:patridge,项目名称:MonoForAndroidFlashlight,代码行数:11,代码来源:FlashlightActivity.cs


示例11: OnPause

		protected override void OnPause ()
		{
			base.OnPause ();

			// Because the Camera object is a shared resource, it's very
			// important to release it when the activity is paused.
			if (mCamera != null) {
				mPreview.PreviewCamera = null;
				mCamera.Release ();
				mCamera = null;
			}
		}
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:12,代码来源:CameraPreview.cs


示例12: CameraPreview

      public CameraPreview(Context context, Camera.IPreviewCallback previewCallback, bool cameraPreviewCallbackWithBuffer)
         : base(context)
      {
         _cameraPreviewCallbackWithBuffer = cameraPreviewCallbackWithBuffer;

         // Install a SurfaceHolder.Callback so we get notified when the
         // underlying surface is created and destroyed.
         _surfaceHolder = Holder;
         _surfaceHolder.AddCallback(this);

         _cameraPreviewCallback = previewCallback;
      }
开发者ID:reidblomquist,项目名称:emgucv,代码行数:12,代码来源:CameraPreview.cs


示例13: CleanUpCamera

 public void CleanUpCamera()
 {
     if (camera != null)
     {
         camera.StopPreview();
         if (cameraPreview != null)
         {
             cameraPreview.PreviewCamera = null;
         }
         camera.Release();
         camera = null;
     }
 }
开发者ID:builttoroam,项目名称:BuildIt,代码行数:13,代码来源:CameraFeedUtility.cs


示例14: SurfaceCreated

	    public void SurfaceCreated (ISurfaceHolder holder)
		{
			try 
			{
				var version = Android.OS.Build.VERSION.SdkInt;

				if (version >= BuildVersionCodes.Gingerbread)
				{
					var numCameras = Android.Hardware.Camera.NumberOfCameras;
					var camInfo = new Android.Hardware.Camera.CameraInfo();
					var found = false;
					
					for (int i = 0; i < numCameras; i++)
					{
						Android.Hardware.Camera.GetCameraInfo(i, camInfo);
						if (camInfo.Facing == CameraFacing.Back)
						{
							camera = Android.Hardware.Camera.Open(i);
							found = true;
							break;
						}
					}
					
					if (!found)
					{
						Android.Util.Log.Debug("ZXing.Net.Mobile", "Finding rear camera failed, opening camera 0...");
						camera = Android.Hardware.Camera.Open(0);
					}
				}
				else
				{
					camera = Android.Hardware.Camera.Open();
				}
				if (camera == null)
					Android.Util.Log.Debug("ZXing.Net.Mobile", "Camera is null :(");
				
				
				//camera = Android.Hardware.Camera.Open ();
				camera.SetPreviewDisplay (holder);
				//camera.SetPreviewCallback (this);
				camera.SetOneShotPreviewCallback(this);

				
			} catch (Exception ex) {
				ShutdownCamera ();
				
				// TODO: log or otherwise handle this exception
				Console.WriteLine("Setup Error: " + ex);
				//throw;
			}
		}
开发者ID:ryanthompson0123,项目名称:ZXing.Net.Mobile,代码行数:51,代码来源:ZXingSurfaceView.cs


示例15: 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


示例16: SurfaceCreated

			public void SurfaceCreated (ISurfaceHolder holder)
			{
				try {
					camera = Camera.Open ();
					camera.SetPreviewDisplay (holder);
					camera.SetPreviewCallback (this);

				} catch (Exception e) {
					ShutdownCamera ();

					// TODO: log or otherwise handle this exception

					throw;
				}
			}
开发者ID:Redth,项目名称:zxing.MonoTouch,代码行数:15,代码来源:QrScannerActivity.cs


示例17: 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


示例18: CameraPreview

        public CameraPreview(Context context, Camera camera,Camera.IPreviewCallback previewCallback) : base(context)
        {
            this.camera = camera;
            this.previewCallback = previewCallback;

            var parameters = this.camera.GetParameters();
            foreach (var p in from f in parameters.SupportedFocusModes where f == Camera.Parameters.FocusModeContinuousPicture select this.camera.GetParameters())
            {
                p.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
                this.camera.SetParameters(p);
            }

            surfaceHolder = base.Holder;
            surfaceHolder.AddCallback(this);

        }
开发者ID:joacar,项目名称:MonoDroid.ZBar,代码行数:16,代码来源:CameraPreview.cs


示例19: Prepare

		public override void Prepare(){
			
			if (camera == null) {
				camera = Camera.Open();
			}
			
			// We reconnect to camera to change flash state if needed
			camera.Reconnect();
			Camera.Parameters parameters = camera.GetParameters();
			parameters.FlashMode = flashState?Camera.Parameters.FlashModeTorch:Camera.Parameters.FlashModeOff;
			camera.SetParameters(parameters);
			camera.SetDisplayOrientation(quality.Orientation);
			camera.StopPreview();
			camera.Unlock();
			base.SetCamera(camera);

			base.SetVideoSource(Android.Media.VideoSource.Camera);
			base.SetOutputFormat(Android.Media.OutputFormat.ThreeGpp);
			base.SetMaxDuration(0);
			base.SetMaxFileSize(int.MaxValue);

			base.SetVideoEncoder(videoEncoder);
			base.SetVideoSize(quality.ResX,quality.ResY);
			base.SetVideoFrameRate(quality.FrameRate);
			base.SetVideoEncodingBitRate(quality.BitRate);


			//SetAudioSource(Android.Media.AudioSource.Mic);
			/*SetVideoSource(Android.Media.VideoSource.Camera);
			
			SetOutputFormat(Android.Media.OutputFormat.ThreeGpp);
			//SetAudioEncoder(Android.Media.AudioEncoder.AmrNb);
			SetVideoEncoder(Android.Media.VideoEncoder.H263);
			SetVideoSize(640,480);
			SetVideoFrameRate(15);
			SetVideoEncodingBitRate(500000);*/

			base.SetPreviewDisplay(surfaceHolder.Surface);
			base.Prepare();
			// Reset flash state to ensure that default behavior is to turn it off
			flashState = false;
			
			// Quality has been updated
			qualityHasChanged = false;
			
		}
开发者ID:seipekm,项目名称:MonoBrick-Communication-Software,代码行数:46,代码来源:VideoStream.cs


示例20: CameraPreview

		public CameraPreview (Context context, Camera camera, Camera.CameraInfo cameraInfo, 
			SurfaceOrientation displayOrientation) :
			base (context)
		{
			// Do not initialize if no camera has been set
			if (camera == null || cameraInfo == null)
				return;
			
			this.camera = camera;
			this.cameraInfo = cameraInfo;
			this.displayOrientation = displayOrientation;

			// Install a SurfaceHolder.Callback so we get notified when the
			// underlying surface is created and destroyed.
			holder = Holder;
			holder.AddCallback (this);
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:17,代码来源:CameraPreview.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hardware.Sensor类代码示例发布时间:2022-05-24
下一篇:
C# Drawables.Drawable类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap