mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-11 16:48:14 +03:00
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using ZXing;
|
|
using ZXing.QrCode;
|
|
|
|
namespace v2rayN.Handler
|
|
{
|
|
/// <summary>
|
|
/// 含有QR码的描述类和包装编码和渲染
|
|
/// </summary>
|
|
public class QRCodeHelper
|
|
{
|
|
public static Image GetQRCode(string strContent)
|
|
{
|
|
Image img = null;
|
|
try
|
|
{
|
|
QrCodeEncodingOptions options = new QrCodeEncodingOptions
|
|
{
|
|
CharacterSet = "UTF-8",
|
|
DisableECI = true, // Extended Channel Interpretation (ECI) 主要用于特殊的字符集。并不是所有的扫描器都支持这种编码。
|
|
ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.M, // 纠错级别
|
|
Width = 500,
|
|
Height = 500,
|
|
Margin = 1
|
|
};
|
|
// options.Hints,更多属性,也可以在这里添加。
|
|
|
|
BarcodeWriter writer = new BarcodeWriter
|
|
{
|
|
Format = BarcodeFormat.QR_CODE,
|
|
Options = options
|
|
};
|
|
Bitmap bmp = writer.Write(strContent);
|
|
img = (Image)bmp;
|
|
return img;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Utils.SaveLog(ex.Message, ex);
|
|
return img;
|
|
}
|
|
}
|
|
}
|
|
}
|