當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。