61 lines
1.9 KiB
C#
Executable File
61 lines
1.9 KiB
C#
Executable File
using ZXing.QrCode.Internal;
|
|
using Shadowsocks.Controller;
|
|
using Shadowsocks.Properties;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Shadowsocks.View
|
|
{
|
|
public partial class QRCodeForm : Form
|
|
{
|
|
private string code;
|
|
|
|
public QRCodeForm(string code)
|
|
{
|
|
this.code = code;
|
|
InitializeComponent();
|
|
this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
|
|
this.Text = I18N.GetString("QRCode");
|
|
}
|
|
|
|
private void GenQR(string ssconfig)
|
|
{
|
|
string qrText = ssconfig;
|
|
QRCode code = ZXing.QrCode.Internal.Encoder.encode(qrText, ErrorCorrectionLevel.M);
|
|
ByteMatrix m = code.Matrix;
|
|
int blockSize = Math.Max(pictureBox1.Height / m.Height, 1);
|
|
Bitmap drawArea = new Bitmap((m.Width * blockSize), (m.Height * blockSize));
|
|
using (Graphics g = Graphics.FromImage(drawArea))
|
|
{
|
|
g.Clear(Color.White);
|
|
using (Brush b = new SolidBrush(Color.Black))
|
|
{
|
|
for (int row = 0; row < m.Width; row++)
|
|
{
|
|
for (int col = 0; col < m.Height; col++)
|
|
{
|
|
if (m[row, col] != 0)
|
|
{
|
|
g.FillRectangle(b, blockSize * row, blockSize * col, blockSize, blockSize);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pictureBox1.Image = drawArea;
|
|
}
|
|
|
|
private void QRCodeForm_Load(object sender, EventArgs e)
|
|
{
|
|
GenQR(code);
|
|
}
|
|
}
|
|
}
|