2016-08-17 4 views
1

내 xamarin.ios 앱에 바코드 스캐너 기능을 추가하려고합니다. Visual Studio에서 개발 중이며 xamarin 구성 요소 저장소의 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 repo에서 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]; 
}