You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

QRCodeForm.cs 3.3 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using QRCode4CS;
  2. using Shadowsocks.Properties;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.IO.Compression;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. namespace Shadowsocks.View
  13. {
  14. public partial class QRCodeForm : Form
  15. {
  16. private string code;
  17. public QRCodeForm(string code)
  18. {
  19. this.code = code;
  20. InitializeComponent();
  21. }
  22. private void GenQR(string ssconfig)
  23. {
  24. <<<<<<< HEAD
  25. string qrText = ssconfig;
  26. QRCode4CS.Options options = new QRCode4CS.Options();
  27. options.Text = qrText;
  28. QRCode4CS.QRCode qrCoded = null;
  29. bool success = false;
  30. foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L})
  31. =======
  32. string qrText = ssconfig;
  33. QRCode4CS.QRCode qrCoded = new QRCode4CS.QRCode(6, QRErrorCorrectLevel.L);
  34. qrCoded.AddData(qrText);
  35. qrCoded.Make();
  36. int blockSize = 5;
  37. Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize));
  38. for (int row = 0; row < qrCoded.GetModuleCount(); row++)
  39. >>>>>>> 7d539d3... add modify detector
  40. {
  41. for (int i = 3; i < 10; i++)
  42. {
  43. try
  44. {
  45. options.TypeNumber = i;
  46. options.CorrectLevel = level;
  47. qrCoded = new QRCode4CS.QRCode(options);
  48. qrCoded.Make();
  49. success = true;
  50. break;
  51. }
  52. catch
  53. {
  54. qrCoded = null;
  55. continue;
  56. }
  57. }
  58. if (success)
  59. break;
  60. }
  61. if (qrCoded == null)
  62. {
  63. return;
  64. }
  65. int blockSize = Math.Max(200 / qrCoded.GetModuleCount(), 1);
  66. Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize));
  67. using (Graphics g = Graphics.FromImage(drawArea))
  68. {
  69. g.Clear(Color.White);
  70. using (Brush b = new SolidBrush(Color.Black))
  71. {
  72. for (int row = 0; row < qrCoded.GetModuleCount(); row++)
  73. {
  74. for (int col = 0; col < qrCoded.GetModuleCount(); col++)
  75. {
  76. if (qrCoded.IsDark(row, col))
  77. {
  78. g.FillRectangle(b, blockSize * row, blockSize * col, blockSize, blockSize);
  79. }
  80. }
  81. }
  82. }
  83. }
  84. pictureBox1.Image = drawArea;
  85. }
  86. private void QRCodeForm_Load(object sender, EventArgs e)
  87. {
  88. GenQR(code);
  89. }
  90. }
  91. }