2016-08-17 68 views
1

xamarin.iosアプリにバーコードスキャナ機能を追加しようとしています。私はVisual Studioから開発しています。私は、xxarinコンポーネントストアからZxing.Net.Mobileコンポーネントを追加しました。Xamarin.iOS ZXing.Net.Mobileバーコードスキャナ

ScanButton.TouchUpInside += async (sender, e) => { 
      //var options = new ZXing.Mobile.MobileBarcodeScanningOptions(); 
      //options.AutoRotate = false; 
      //options.PossibleFormats = new List<ZXing.BarcodeFormat>() { 
      // ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13 
      //}; 

      var scanner = new ZXing.Mobile.MobileBarcodeScanner(this); 
      //scanner.TopText = "Hold camera up to barcode to scan"; 
      //scanner.BottomText = "Barcode will automatically scan"; 
      //scanner.UseCustomOverlay = false; 
      scanner.FlashButtonText = "Flash"; 
      scanner.CancelButtonText = "Cancel"; 
      scanner.Torch(true); 
      scanner.AutoFocus(); 

      var result = await scanner.Scan(true); 
      HandleScanResult(result); 
     }; 

void HandleScanResult(ZXing.Result result) 
    { 
     if (result != null && !string.IsNullOrEmpty(result.Text)) 
      TextField.Text = result.Text; 
    } 

問題は、私はスキャンボタンをタップすると、キャプチャビューが正しく表示されていることですが、私は捕獲しようとした場合、バーコード何も起こらないと:サンプルに示すように

私はそれを実装しましたスキャナがバーコードを認識しないようです。

誰かがこの問題を経験しましたか?どのように私はそれを働かせることができますか?

ご協力いただきありがとうございます。

+0

あなたはここにしようとしたのですか? https://components.xamarin.com/gettingstarted/zxing.net.mobileサンプルコードがあります(私はバーコードスキャナーでの経験は一度もありません) – unbalanced

+0

はい、サンプルコードに従っていますが動作しません。私はgithubリポジトリからiosサンプルを実行しようとしましたが、それもうまくいきません。それは私のipad 2(私はテストするためにこれを使用している)の問題かもしれません? – Androidian

+0

これをフォローできますか? https://blog.xamarin.com/barcode-scanning-made-easy-with-zxing-net-for-xamarin-forms/ – unbalanced

答えて

1

私は同様の質問hereに答えました。デフォルトのカメラ解像度が低く設定されているため、バーコードを読み取ることができませんでした。この場合の具体的な実装は次のようになります。

ScanButton.TouchUpInside += async (sender, e) => { 
     var options = new ZXing.Mobile.MobileBarcodeScanningOptions { 
      CameraResolutionSelector = HandleCameraResolutionSelectorDelegate 
     }; 

     var scanner = new ZXing.Mobile.MobileBarcodeScanner(this); 
     . 
     . 
     . 
     scanner.AutoFocus(); 

     //call scan with options created above 
     var result = await scanner.Scan(options, true); 
     HandleScanResult(result); 
    }; 

そしてHandleCameraResolutionSelectorDelegateため、その後の定義:

CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions) 
{ 
    //Don't know if this will ever be null or empty 
    if (availableResolutions == null || availableResolutions.Count < 1) 
     return new CameraResolution() { Width = 800, Height = 600 }; 

    //Debugging revealed that the last element in the list 
    //expresses the highest resolution. This could probably be more thorough. 
    return availableResolutions [availableResolutions.Count - 1]; 
} 
関連する問題