-
Notifications
You must be signed in to change notification settings - Fork 77
/
MainWindow.xaml.cs
88 lines (79 loc) · 2.45 KB
/
MainWindow.xaml.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// QR code generator library (.NET)
// https://github.com/manuelbl/QrCodeGenerator
//
// Copyright (c) 2021 Manuel Bleichenbacher
// Licensed under MIT License
// https://opensource.org/licenses/MIT
//
using System;
using System.Windows;
namespace Net.Codecrete.QrCodeGenerator.Demo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private string _text = "QR code text";
private int _borderWidth = 3;
private QrCode.Ecc _errorCorrection = QrCode.Ecc.Medium;
private readonly Tuple<string, QrCode.Ecc>[] _errorCorrectionLevels =
{
new Tuple<string, QrCode.Ecc>("Low", QrCode.Ecc.Low),
new Tuple<string, QrCode.Ecc>("Medium", QrCode.Ecc.Medium),
new Tuple<string, QrCode.Ecc>("Quartile", QrCode.Ecc.Quartile),
new Tuple<string, QrCode.Ecc>("High", QrCode.Ecc.High)
};
public MainWindow()
{
InitializeComponent();
UpdateQrCode();
}
public int BorderWidth
{
get { return _borderWidth; }
set
{
_borderWidth = value;
UpdateQrCode();
}
}
public string Text
{
get { return _text; }
set
{
_text = value;
UpdateQrCode();
}
}
public Tuple<string, QrCode.Ecc>[] ErrorCorrectionLevels
{
get { return _errorCorrectionLevels; }
}
public QrCode.Ecc ErrorCorrection
{
get { return _errorCorrection; }
set
{
_errorCorrection = value;
UpdateQrCode();
}
}
private void UpdateQrCode()
{
var qrCode = QrCode.EncodeText(_text, ErrorCorrection);
QrCodeImage.Source = QrCodeDrawing.CreateDrawing(qrCode, 192, BorderWidth);
}
private void CopyButton_Click(object sender, RoutedEventArgs e)
{
// put the QR code on the clipboard as a bitmap
var qrCode = QrCode.EncodeText(_text, ErrorCorrection);
var bitmap = QrCodeDrawing.CreateBitmapImage(qrCode, 20, BorderWidth);
var dataObject = new DataObject();
dataObject.SetData(DataFormats.Bitmap, bitmap);
Clipboard.SetDataObject(dataObject);
}
}
}