From 8b9ce384b26c414db32f98e94e088f5334869c2d Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期三, 13 十一月 2019 15:36:28 +0800
Subject: [PATCH] 全部合并了代码,安卓和 IOS 都测试通过了

---
 ZigbeeApp/GateWay.Droid/Application.cs |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/ZigbeeApp/GateWay.Droid/Application.cs b/ZigbeeApp/GateWay.Droid/Application.cs
index b200e36..0a7f5d4 100755
--- a/ZigbeeApp/GateWay.Droid/Application.cs
+++ b/ZigbeeApp/GateWay.Droid/Application.cs
@@ -15,7 +15,9 @@
 using Microsoft.AppCenter.Analytics;
 using Microsoft.AppCenter.Crashes;
 using Com.Tencent.MM.Sdk.Openapi;
-
+using ZXing.Mobile;
+using System.IO;
+
 namespace com.hdl.home
 {
 
@@ -273,3 +275,59 @@
         }
     }
 }
+
+namespace Shared
+{
+    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);
+                }
+            });
+        }
+
+        public static byte[] BytesFromText(string text, int width = 300, int height = 300)
+        {
+            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
+            {
+                Format = ZXing.BarcodeFormat.QR_CODE,
+                Options = new ZXing.Common.EncodingOptions
+                {
+                    Width = width,
+                    Height = height,
+                    Margin = 0
+                }
+            };
+
+            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
+            var bitmap = barcodeWriter.Write(text);
+            using (var stream = new MemoryStream())
+            {
+                bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream);  // this is the diff between iOS and Android
+                stream.Position = 0;
+                return stream.ToArray();
+            }
+        }
+    }
+}

--
Gitblit v1.8.0