Example #1
0
        void regenerate()
        {
            if (formsView != null && formsView.BarcodeValue != null)
            {
                var writer = new ZXing.Mobile.BarcodeWriter();

                if (formsView != null && formsView.BarcodeOptions != null)
                {
                    writer.Options = formsView.BarcodeOptions;
                }
                if (formsView != null && formsView.BarcodeFormat != null)
                {
                    writer.Format = formsView.BarcodeFormat;
                }

                var value = formsView != null ? formsView.BarcodeValue : string.Empty;

                Device.BeginInvokeOnMainThread(() =>
                {
                    var image = writer.Write(value);

                    imageView.Source = image;
                });
            }
        }
Example #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <ZXingBarcodeImageView> e)
        {
            formsView = Element;

            if (imageView == null)
            {
                imageView = new ImageView(Xamarin.Forms.Forms.Context);

                base.SetNativeControl(imageView);
            }

            if (formsView != null && formsView.BarcodeValue != null)
            {
                var writer = new ZXing.Mobile.BarcodeWriter();

                if (formsView != null && formsView.BarcodeOptions != null)
                {
                    writer.Options = formsView.BarcodeOptions;
                }
                if (formsView != null && formsView.BarcodeFormat != null)
                {
                    writer.Format = formsView.BarcodeFormat;
                }

                var value = formsView != null ? formsView.BarcodeValue : string.Empty;

                var image = writer.Write(value);

                imageView.SetImageBitmap(image);
            }

            base.OnElementChanged(e);
        }
Example #3
0
		public virtual Stream Create(BarCodeCreateConfiguration cfg) {
#if __ANDROID__
            var writer = new ZXing.BarcodeWriter {
				Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), cfg.Format.ToString()),
                Encoder = new MultiFormatWriter(),
                Options = new EncodingOptions {
					Height = cfg.Height,
					Margin = cfg.Margin,
					Width = cfg.Height,
					PureBarcode = cfg.PureBarcode
                }
            };
#endif
#if __IOS__
            var writer = new ZXing.Mobile.BarcodeWriter
            {
                Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), cfg.Format.ToString()),
                Encoder = new MultiFormatWriter(),
                Options = new EncodingOptions
                {
                    Height = cfg.Height,
                    Margin = cfg.Margin,
                    Width = cfg.Height,
                    PureBarcode = cfg.PureBarcode
                }
            };
#endif
            return this.ToImageStream(writer, cfg);
        }
            private UIImage GetQRCode(string url)
            {
                var writer = new ZXing.Mobile.BarcodeWriter {
                    Format  = BarcodeFormat.QR_CODE,
                    Options = new ZXing.Common.EncodingOptions {
                        Height = 250,
                        Width  = 250
                    }
                };

                return(writer.Write(url));
            }
Example #5
0
        public Stream ConvertImageStream(string text, int width = 500, int height = 500)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = width,
                    Height = height,
                    Margin = 2
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(text);
            var stream = new MemoryStream();

            bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);  // this is the diff between iOS and Android
            stream.Position = 0;
            return(stream);
        }
Example #6
0
        void regenerate()
        {
            if (formsView != null && formsView.BarcodeValue != null)
            {
                var writer = new ZXing.Mobile.BarcodeWriter();

                if (formsView != null && formsView.BarcodeOptions != null)
                {
                    writer.Options = formsView.BarcodeOptions;
                }
                if (formsView != null && formsView.BarcodeFormat != null)
                {
                    writer.Format = formsView.BarcodeFormat;
                }

                var value = formsView != null ? formsView.BarcodeValue : string.Empty;

                var image = writer.Write(value);

                imageView.SetImageBitmap(image);
            }
        }
Example #7
0
        public Bitmap GenerateQrImage(string content, int width, int height)
        {
            var writer = new ZXing.Mobile.BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height      = height,
                    Width       = width,
                    Margin      = 0,
                    PureBarcode = true,
                }
            };

            writer.Renderer = new ZXing.Mobile.BitmapRenderer {
                Background = Color.Red, Foreground = Color.Black
            };
            var bitmap = writer.Write(content);

            //var stream = new MemoryStream();
            //bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);  // this is the diff between iOS and Android
            //stream.Position = 0;
            return(bitmap);
        }
Example #8
0
        protected SensusServiceHelper()
        {
            if (SINGLETON != null)
                throw new SensusException("Attempted to construct new service helper when singleton already existed.");

            _stopped = true;
            _registeredProtocols = new ObservableCollection<Protocol>();
            _runningProtocolIds = new List<string>();
            _healthTestCallbackId = null;
            _idCallback = new Dictionary<string, ScheduledCallback>();
            _hasher = new SHA256Managed();
            _pointsOfInterest = new List<PointOfInterest>();

            // ensure that the entire QR code is always visible by using 90% the minimum screen dimension as the QR code size.
            #if __ANDROID__
            int qrCodeSize = (int)(0.9 * Math.Min(XLabs.Platform.Device.Display.Metrics.WidthPixels, XLabs.Platform.Device.Display.Metrics.HeightPixels));
            #elif __IOS__
            int qrCodeSize = (int)(0.9 * Math.Min(AppleDevice.CurrentDevice.Display.Height, AppleDevice.CurrentDevice.Display.Width));
            #else
            #error "Unrecognized platform"
            #endif

            _barcodeWriter = new ZXing.Mobile.BarcodeWriter
            { 
                Format = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height = qrCodeSize,
                    Width = qrCodeSize
                }
            };

            if (!Directory.Exists(SHARE_DIRECTORY))
                Directory.CreateDirectory(SHARE_DIRECTORY); 

            #if DEBUG || UNIT_TESTING
            LoggingLevel loggingLevel = LoggingLevel.Debug;
            #elif RELEASE
            LoggingLevel loggingLevel = LoggingLevel.Normal;
            #else
            #error "Unrecognized configuration."
            #endif

            _logger = new Logger(LOG_PATH, loggingLevel, Console.Error);
            _logger.Log("Log file started at \"" + LOG_PATH + "\".", LoggingLevel.Normal, GetType());

            GpsReceiver.Get().Initialize(Geolocator);  // initialize GPS receiver with platform-specific geolocator

            if (Insights.IsInitialized)
                _logger.Log("Xamarin Insights is already initialized.", LoggingLevel.Normal, GetType());
            else if (string.IsNullOrWhiteSpace(XAMARIN_INSIGHTS_APP_KEY))
                _logger.Log("Xamarin Insights API key is empty. Not initializing.", LoggingLevel.Normal, GetType());  // xamarin allows to initialize with a null key, which fails with exception but results in IsInitialized being true. prevent that here.
            else
            {
                try
                {
                    _logger.Log("Initializing Xamarin Insights.", LoggingLevel.Normal, GetType());

                    // wait for startup crash to be logged -- https://insights.xamarin.com/docs
                    Insights.HasPendingCrashReport += (sender, isStartupCrash) =>
                    {
                        if (isStartupCrash)
                            Insights.PurgePendingCrashReports().Wait();
                    };

                    InitializeXamarinInsights();  
                }
                catch (Exception ex)
                {
                    _logger.Log("Failed to initialize Xamarin insights:  " + ex.Message, LoggingLevel.Normal, GetType());
                }
            }
        }