2016-05-24 8 views

答えて

7

以下のコードを試すことができます。 は、溶液中のすべてのプロジェクトにzxingライブラリ/コンポーネントを追加します。これは、前方にかなりストレートです

public class Home : ContentPage 
{ 
    string message = ""; 
    public Home() 
    { 
     //Intialize the button 
     Button btnScan = new Button 
     { 
      Text = "Start Scan", 
      BackgroundColor = Color.FromRgb(207, 197, 159), 
      TextColor = Color.White, 
      BorderRadius = 5, 
      TranslationY = 120 
     }; 
     //Attach the click event 
     btnScan.Clicked += btnScan_Clicked; 

     this.Content = new StackLayout 
     { 
      BackgroundColor = Color.FromRgb(150, 172, 135), 
      Spacing = 10, 
      Padding = 25, 
      Children = 
      { 
       btnScan 
      } 
     }; 
    } 

    async void btnScan_Clicked(object sender, EventArgs e) 
    { 
     var scanner = new MobileBarcodeScanner(); 
     scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; 
     scanner.BottomText = "Wait for the barcode to automatically scan!"; 

     //This will start scanning 
     ZXing.Result result = await scanner.Scan(); 

     //Show the result returned. 
     HandleResult(result); 
    } 

    void HandleResult(ZXing.Result result) 
    { 
     var msg = "No Barcode!"; 
     if (result != null) 
     { 
      msg = "Barcode: " + result.Text + " (" + result.BarcodeFormat + ")"; 
     } 

     DisplayAlert("", msg, "Ok"); 
    } 
} 
+1

それは動作します。カスタムビューを使用してバーコードをキャプチャするにはどうすればよいですか? –

+1

https://components.xamarin.com/gettingstarted/zxing.net.mobile.forms。ここでカスタムオーバーレイを検索してください。カスタムビューについてはわかりませんが、このカスタムオーバーレイを使用すると、必要なものを上に追加できます。 –

+0

これのためのサンプルを与えることができます –