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 1.9 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
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using ZXing.QrCode.Internal;
  2. using Shadowsocks.Controller;
  3. using Shadowsocks.Properties;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.IO.Compression;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. namespace Shadowsocks.View
  14. {
  15. public partial class QRCodeForm : Form
  16. {
  17. private string code;
  18. public QRCodeForm(string code)
  19. {
  20. this.code = code;
  21. InitializeComponent();
  22. this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
  23. this.Text = I18N.GetString("QRCode");
  24. }
  25. private void GenQR(string ssconfig)
  26. {
  27. string qrText = ssconfig;
  28. QRCode code = ZXing.QrCode.Internal.Encoder.encode(qrText, ErrorCorrectionLevel.M);
  29. ByteMatrix m = code.Matrix;
  30. int blockSize = Math.Max(pictureBox1.Height / m.Height, 1);
  31. Bitmap drawArea = new Bitmap((m.Width * blockSize), (m.Height * blockSize));
  32. using (Graphics g = Graphics.FromImage(drawArea))
  33. {
  34. g.Clear(Color.White);
  35. using (Brush b = new SolidBrush(Color.Black))
  36. {
  37. for (int row = 0; row < m.Width; row++)
  38. {
  39. for (int col = 0; col < m.Height; col++)
  40. {
  41. if (m[row, col] != 0)
  42. {
  43. g.FillRectangle(b, blockSize * row, blockSize * col, blockSize, blockSize);
  44. }
  45. }
  46. }
  47. }
  48. }
  49. pictureBox1.Image = drawArea;
  50. }
  51. private void QRCodeForm_Load(object sender, EventArgs e)
  52. {
  53. GenQR(code);
  54. }
  55. }
  56. }