public ScanContinuously ( Android.Content.Context context, ZXing.Mobile.MobileBarcodeScanningOptions options, Action |
||
context | Android.Content.Context | |
options | ZXing.Mobile.MobileBarcodeScanningOptions | |
scanHandler | Action |
|
Результат | void |
public void ScanQRCodeContinuously(Func <IMobileBarcodeScanner, ZXing.Result, bool> action) { var scanner = new ZXing.Mobile.MobileBarcodeScanner(); scanner.ScanContinuously((result) => { //scanner.Torch(true); var url = result.Text; if (action == null || action(scanner, result)) { scanner.Cancel(); } }); //scanner.Torch(true); }
public override void ViewDidLoad() { //Create a new instance of our scanner scanner = new MobileBarcodeScanner(this.NavigationController); Root = new RootElement ("ZXing.Net.Mobile") { new Section { new StyledStringElement ("Scan with Default View", async () => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold camera up to barcode to scan"; scanner.BottomText = "Barcode will automatically scan"; //Start scanning var result = await scanner.Scan (); HandleScanResult(result); }), new StyledStringElement ("Scan Continuously", () => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //Tell our scanner to use our custom overlay scanner.UseCustomOverlay = true; scanner.CustomOverlay = customOverlay; var opt = new MobileBarcodeScanningOptions (); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously (opt, true, HandleScanResult); }), new StyledStringElement ("Scan with Custom View", async () => { //Create an instance of our custom overlay customOverlay = new CustomOverlayView(); //Wireup the buttons from our custom overlay customOverlay.ButtonTorch.TouchUpInside += delegate { scanner.ToggleTorch(); }; customOverlay.ButtonCancel.TouchUpInside += delegate { scanner.Cancel(); }; //Tell our scanner to use our custom overlay scanner.UseCustomOverlay = true; scanner.CustomOverlay = customOverlay; var result = await scanner.Scan (); HandleScanResult(result); }), new StyledStringElement ("Scan with AVCapture Engine", async () => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold camera up to barcode to scan"; scanner.BottomText = "Barcode will automatically scan"; //Start scanning var result = await scanner.Scan (true); HandleScanResult (result); }), new StyledStringElement ("Generate Barcode", () => { NavigationController.PushViewController (new ImageViewController (), true); }) } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Initialize the scanner first so we can track the current context MobileBarcodeScanner.Initialize (Application); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); //Create a new instance of our Scanner scanner = new MobileBarcodeScanner(); hideImage = this.FindViewById<Button>(Resource.Id.hideImageBtn); previewImage = this.FindViewById<ImageView>(Resource.Id.previewImage); hideImage.Visibility = ViewStates.Gone; previewImage.Visibility = ViewStates.Gone; hideImage.Click += (object sender, System.EventArgs e) => { hideImage.Visibility = ViewStates.Gone; previewImage.Visibility = ViewStates.Gone; }; buttonScanDefaultView = this.FindViewById<Button>(Resource.Id.buttonScanDefaultView); buttonScanDefaultView.Click += async delegate { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; //Start scanning var options = new ZXing.Mobile.MobileBarcodeScanningOptions(); options.PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.AZTEC }; var result = await scanner.Scan(options); HandleScanResult(result); }; buttonContinuousScan = FindViewById<Button> (Resource.Id.buttonScanContinuous); buttonContinuousScan.Click += delegate { scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; scanner.BottomText = "Wait for the barcode to automatically scan!"; var opt = new MobileBarcodeScanningOptions (); opt.DelayBetweenContinuousScans = 3000; //Start scanning scanner.ScanContinuously(opt, HandleScanResult); }; Button flashButton; View zxingOverlay; buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView); buttonScanCustomView.Click += async delegate { //Tell our scanner we want to use a custom overlay instead of the default scanner.UseCustomOverlay = true; //Inflate our custom overlay from a resource layout zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null); //Find the button from our resource layout and wire up the click event flashButton = zxingOverlay.FindViewById<Button>(Resource.Id.buttonZxingFlash); flashButton.Click += (sender, e) => scanner.ToggleTorch(); //Set our custom overlay scanner.CustomOverlay = zxingOverlay; //Start scanning! var result = await scanner.Scan(); HandleScanResult(result); }; buttonFragmentScanner = FindViewById<Button> (Resource.Id.buttonFragment); buttonFragmentScanner.Click += delegate { StartActivity (typeof (FragmentActivity)); }; buttonGenerate = FindViewById<Button> (Resource.Id.buttonGenerate); buttonGenerate.Click += delegate { StartActivity (typeof (ImageActivity)); }; }