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


C# MobileBarcodeScanningOptions.GetResolution方法代码示例

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


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

示例1: StartScanningAsync

        public async Task StartScanningAsync (Action<Result> scanResultCallback, MobileBarcodeScanningOptions options = null)
        {
            this.callback = scanResultCallback;
            this.scanningOptions = options ?? MobileBarcodeScanningOptions.Default;

            lastPreviewAnalysis = DateTime.UtcNow.AddMilliseconds (this.scanningOptions.InitialDelayBeforeAnalyzingFrames);
            isAnalyzing = true;

            Console.WriteLine ("StartScanning");

            CheckCameraPermissions ();

            var perf = PerformanceCounter.Start ();

            GetExclusiveAccess ();

            try {
                var version = Build.VERSION.SdkInt;

                if (version >= BuildVersionCodes.Gingerbread) {
                    Android.Util.Log.Debug (MobileBarcodeScanner.TAG, "Checking Number of cameras...");

                    var numCameras = Camera.NumberOfCameras;
                    var camInfo = new Camera.CameraInfo ();
                    var found = false;
                    Android.Util.Log.Debug (MobileBarcodeScanner.TAG, "Found " + numCameras + " cameras...");

                    var whichCamera = CameraFacing.Back;

                    if (this.scanningOptions.UseFrontCameraIfAvailable.HasValue && this.scanningOptions.UseFrontCameraIfAvailable.Value)
                        whichCamera = CameraFacing.Front;

                    for (int i = 0; i < numCameras; i++) {
                        Camera.GetCameraInfo (i, camInfo);
                        if (camInfo.Facing == whichCamera) {
                            Android.Util.Log.Debug (MobileBarcodeScanner.TAG, "Found " + whichCamera + " Camera, opening...");
                            camera = Camera.Open (i);
                            cameraId = i;
                            found = true;
                            break;
                        }
                    }

                    if (!found) {
                        Android.Util.Log.Debug (MobileBarcodeScanner.TAG, "Finding " + whichCamera + " camera failed, opening camera 0...");
                        camera = Camera.Open (0);
                        cameraId = 0;
                    }
                } else {
                    camera = Camera.Open ();
                }

                if (camera == null)
                    Android.Util.Log.Debug (MobileBarcodeScanner.TAG, "Camera is null :(");

                camera.SetPreviewCallback (this);

            } catch (Exception ex) {
                ShutdownCamera ();

                Console.WriteLine ("Setup Error: " + ex);
            }

            PerformanceCounter.Stop (perf, "Camera took {0}ms");

            if (!surfaceChanged)
                await waitSurface.WaitAsync ();
            
            if (camera == null)
                return;

            perf = PerformanceCounter.Start ();

            var parameters = camera.GetParameters ();
            parameters.PreviewFormat = ImageFormatType.Nv21;


            var availableResolutions = new List<CameraResolution> ();
            foreach (var sps in parameters.SupportedPreviewSizes) {
                availableResolutions.Add (new CameraResolution {
                    Width = sps.Width,
                    Height = sps.Height
                });
            }

            // Try and get a desired resolution from the options selector
            var resolution = scanningOptions.GetResolution (availableResolutions);

            // If the user did not specify a resolution, let's try and find a suitable one
            if (resolution == null) {
                // Loop through all supported sizes
                foreach (var sps in parameters.SupportedPreviewSizes) {

                    // Find one that's >= 640x360 but <= 1000x1000
                    // This will likely pick the *smallest* size in that range, which should be fine
                    if (sps.Width >= 640 && sps.Width <= 1000 && sps.Height >= 360 && sps.Height <= 1000) {
                        resolution = new CameraResolution {
                            Width = sps.Width,
                            Height = sps.Height
                        };
//.........这里部分代码省略.........
开发者ID:yiji,项目名称:ZXing.Net.Mobile,代码行数:101,代码来源:ZXingSurfaceView.cs


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