You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.2 KiB
85 lines
3.2 KiB
#if NET40 || NET461
|
|
|
|
using Apewer.Internals.QrCode;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Apewer.Internals.QrCode
|
|
{
|
|
|
|
internal sealed class QRCodeUtility
|
|
{
|
|
|
|
public static Bitmap Generate(string argText, int argBlock, QRCodeGenerator.ECCLevel argEccLevel)
|
|
{
|
|
var text = argText ?? "";
|
|
var block = argBlock > 1 ? argBlock : 1;
|
|
var ecclevel = argEccLevel;
|
|
|
|
try
|
|
{
|
|
var generator = new QRCodeGenerator();
|
|
var content = generator.CreateQrCode(text, ecclevel);
|
|
var qrcode = new QRCode(content);
|
|
var bitmap = qrcode.GetGraphic(block);
|
|
return bitmap;
|
|
}
|
|
catch { return null; }
|
|
}
|
|
|
|
/// <summary>生成含有 7% 容错区域的二维码图像,默认色块边长为 10 像素,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateL(string argText)
|
|
{
|
|
return Generate(argText, 10, QRCodeGenerator.ECCLevel.L);
|
|
}
|
|
|
|
/// <summary>生成含有 7% 容错区域的二维码图像,可指定每个色块的边长,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateL(string argText, int argBlock)
|
|
{
|
|
return Generate(argText, argBlock, QRCodeGenerator.ECCLevel.L);
|
|
}
|
|
|
|
/// <summary>生成含有 15% 容错区域的二维码图像,默认色块边长为 10 像素,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateM(string argText)
|
|
{
|
|
return Generate(argText, 10, QRCodeGenerator.ECCLevel.M);
|
|
}
|
|
|
|
/// <summary>生成含有 15% 容错区域的二维码图像,可指定每个色块的边长,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateM(string argText, int argBlock)
|
|
{
|
|
return Generate(argText, argBlock, QRCodeGenerator.ECCLevel.M);
|
|
}
|
|
|
|
/// <summary>生成含有 25% 容错区域的二维码图像,默认色块边长为 10 像素,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateQ(string argText)
|
|
{
|
|
return Generate(argText, 10, QRCodeGenerator.ECCLevel.Q);
|
|
}
|
|
|
|
/// <summary>生成含有 25% 容错区域的二维码图像,可指定每个色块的边长,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateQ(string argText, int argBlock)
|
|
{
|
|
return Generate(argText, argBlock, QRCodeGenerator.ECCLevel.Q);
|
|
}
|
|
|
|
/// <summary>生成含有 30% 容错区域的二维码图像,默认色块边长为 10 像素,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateH(string argText)
|
|
{
|
|
return Generate(argText, 10, QRCodeGenerator.ECCLevel.H);
|
|
}
|
|
|
|
/// <summary>生成含有 30% 容错区域的二维码图像,可指定每个色块的边长,失败时返回 NULL 值。</summary>
|
|
public static Bitmap GenerateH(string argText, int argBlock)
|
|
{
|
|
return Generate(argText, argBlock, QRCodeGenerator.ECCLevel.H);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|