wxr
2020-06-16 f6fd8acd7c53c44187e70b4709443318a628f4b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Drawing;
using System.IO;
 
 
//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 = 10
//                }
//            };
 
//            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();
//            }
//        }
//    }
//}