| | |
| | | using HDL_ON_iOS; |
| | | using Shared; |
| | | using ZXing.Mobile; |
| | | |
| | | using HDL.Shared.IOS.ScanQRCode; |
| | | namespace HDL_ON |
| | | { |
| | | public class Scan |
| | |
| | | |
| | | } |
| | | |
| | | static MobileBarcodeScanner scanner; |
| | | public async void OpenScan(Action<string> action) |
| | | void ScanResult(string result) |
| | | { |
| | | string cancel = "取消"; |
| | | string flashText = ""; |
| | | string titleText = "二维码扫描"; |
| | | if (Language.CurrentLanguage != "Chinese") |
| | | { |
| | | cancel = "Cancel"; |
| | | flashText = ""; |
| | | titleText = "Scan"; |
| | | } |
| | | |
| | | if (scanner == null) |
| | | { |
| | | var mZXingOverlayView = new ZXingOverlayView(cancel, flashText, titleText); |
| | | scanner = new MobileBarcodeScanner(AppDelegate.rootViewController) { FlashButtonText = flashText, TopText = titleText, BottomText = "", CancelButtonText = cancel }; |
| | | scanner.UseCustomOverlay = true; |
| | | |
| | | scanner.CustomOverlay = mZXingOverlayView; |
| | | var bOn = false; |
| | | mZXingOverlayView.OnCancel += () => |
| | | { |
| | | scanner?.Cancel(); |
| | | }; |
| | | |
| | | mZXingOverlayView.OnTorch += () => |
| | | { |
| | | bOn = !bOn; |
| | | scanner?.Torch(bOn); |
| | | }; |
| | | |
| | | } |
| | | |
| | | var result = await scanner.Scan(); |
| | | |
| | | if (result != null) |
| | | { |
| | | action?.Invoke(result.Text); |
| | | action?.Invoke(result); |
| | | } |
| | | else |
| | | { |
| | | action?.Invoke(null); |
| | | Console.WriteLine("二维码返回值为null"); |
| | | } |
| | | |
| | | } |
| | | |
| | | static MobileBarcodeScanner scanner; |
| | | |
| | | |
| | | Action<string> action; |
| | | |
| | | public void OpenScan(Action<string> action) |
| | | { |
| | | this.action = action; |
| | | |
| | | string cancel = "取消"; |
| | | //string flashText = ""; |
| | | string titleText = "二维码扫描"; |
| | | if (Language.CurrentLanguage != "Chinese") |
| | | { |
| | | cancel = "Cancel"; |
| | | //flashText = ""; |
| | | titleText = "Scan"; |
| | | } |
| | | var d1 = new HDLQRCodeScanFinish(ScanResult); |
| | | HDL.Shared.IOS.ScanQRCode.HDLScanQRCodeSDK.SharedInstance().ScanQRCodeWith(cancel, titleText, d1); |
| | | |
| | | |
| | | |
| | | //if (scanner == null) |
| | | //{ |
| | | // var mZXingOverlayView = new ZXingOverlayView(cancel, flashText, titleText); |
| | | // scanner = new MobileBarcodeScanner(AppDelegate.rootViewController) { FlashButtonText = flashText, TopText = titleText, BottomText = "", CancelButtonText = cancel }; |
| | | // scanner.UseCustomOverlay = true; |
| | | |
| | | // scanner.CustomOverlay = mZXingOverlayView; |
| | | // var bOn = false; |
| | | // mZXingOverlayView.OnCancel += () => |
| | | // { |
| | | // scanner?.Cancel(); |
| | | // }; |
| | | |
| | | // mZXingOverlayView.OnTorch += () => |
| | | // { |
| | | // bOn = !bOn; |
| | | // scanner?.Torch(bOn); |
| | | // }; |
| | | |
| | | //} |
| | | |
| | | //var result = await scanner.Scan(); |
| | | |
| | | //if (result != null) |
| | | //{ |
| | | // action?.Invoke(result.Text); |
| | | //} |
| | | //else |
| | | //{ |
| | | // action?.Invoke(null); |
| | | // Console.WriteLine("二维码返回值为null"); |
| | | //} |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | public static byte[] BytesFromText(string text, int width = 300, int height = 300) |