protected void GenerateQRCode() { if (_borderQRCode == null || _qrCodeRect == null) return; if (string.IsNullOrWhiteSpace(ItemURL)) { _borderQRCode.Visibility = Visibility.Collapsed; return; } try { QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode; if (encoder.TryEncode(ItemURL, out qrCode)) { DrawingBrushRenderer dRenderer = new DrawingBrushRenderer(new FixedModuleSize(2, QuietZoneModules.Two), System.Windows.Media.Brushes.Black, System.Windows.Media.Brushes.White); System.Windows.Media.DrawingBrush dBrush = dRenderer.DrawBrush(qrCode.Matrix); _qrCodeRect.Fill = dBrush; _borderQRCode.Visibility = System.Windows.Visibility.Visible; } else { _borderQRCode.Visibility = System.Windows.Visibility.Collapsed; } } catch { _borderQRCode.Visibility = System.Windows.Visibility.Collapsed; } }
void DisplayQRCode(string imageUrl) { imageUrl = Common.UrlHelper.GetCorrectedStreamURL(imageUrl); if (string.IsNullOrWhiteSpace(imageUrl)) { brdrQRCode.Visibility = System.Windows.Visibility.Collapsed; return; } try { QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode; if (encoder.TryEncode(imageUrl, out qrCode)) { DrawingBrushRenderer dRenderer = new DrawingBrushRenderer(new FixedModuleSize(2, QuietZoneModules.Two), Brushes.Black, Brushes.White); DrawingBrush dBrush = dRenderer.DrawBrush(qrCode.Matrix); rectQRCode.Fill = dBrush; brdrQRCode.Visibility = System.Windows.Visibility.Visible; } else { brdrQRCode.Visibility = System.Windows.Visibility.Collapsed; } } catch { brdrQRCode.Visibility = System.Windows.Visibility.Collapsed; } }