| | |
| | | { |
| | | public static class QRCode |
| | | { |
| | | static ZXing.Mobile.MobileBarcodeScanner scanner; |
| | | public static void ScanQRcode(Action<string> action) |
| | | { |
| | | ((BaseActivity)Shared.Application.Activity).SetCamera(async (obj) => { |
| | | if (obj) |
| | | { |
| | | if (scanner == null) |
| | | { |
| | | MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application); |
| | | scanner = new ZXing.Mobile.MobileBarcodeScanner(); |
| | | } |
| | | |
| | | var result = await scanner.Scan(); |
| | | |
| | | if (result != null) |
| | | action?.Invoke(result.Text); |
| | | else |
| | | action?.Invoke(null); |
| | | |
| | | } |
| | | else |
| | | { |
| | | action?.Invoke(null); |
| | | } |
| | | }); |
| | | static ZXing.Mobile.MobileBarcodeScanner scanner;
|
| | | public static void ScanQRcode(Action<string> action, string cancel = "取消", string flashText = "闪光灯", string titleText = "二维码扫描")
|
| | | {
|
| | | ((BaseActivity)Shared.Application.Activity).SetCamera(async (obj) =>
|
| | | {
|
| | | if (obj)
|
| | | {
|
| | | if (scanner == null)
|
| | | {
|
| | | MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application);
|
| | | var mZXingCustomScanView = new GateWay.Droid.ZXingCustomScanView(Shared.Application.Activity.Application);
|
| | | mZXingCustomScanView.cancelTextView.Text = cancel;
|
| | | mZXingCustomScanView.flashTextView.Text = flashText;
|
| | | mZXingCustomScanView.titleTextView.Text = titleText;
|
| | | var bOn = false;
|
| | | scanner = new ZXing.Mobile.MobileBarcodeScanner()
|
| | | {
|
| | | UseCustomOverlay = true,
|
| | | CustomOverlay = mZXingCustomScanView
|
| | | };
|
| | |
|
| | | mZXingCustomScanView.OnCancel += () => {
|
| | |
|
| | | scanner?.Cancel();
|
| | | };
|
| | |
|
| | | mZXingCustomScanView.OnTorch += () =>
|
| | | {
|
| | | bOn = !bOn;
|
| | | scanner?.Torch(bOn);
|
| | | };
|
| | | }
|
| | |
|
| | | var result = await scanner.Scan();
|
| | |
|
| | | if (result != null)
|
| | | action?.Invoke(result.Text);
|
| | | else
|
| | | action?.Invoke(null);
|
| | |
|
| | | }
|
| | | else
|
| | | {
|
| | | action?.Invoke(null);
|
| | | }
|
| | | });
|
| | | } |
| | | |
| | | public static byte[] BytesFromText(string text, int width = 300, int height = 300) |