PKHeX/PKHeX.Drawing.Misc/QR/QREncode.cs
Kurt d47bb1d297
Update .NET Runtime to .NET 8.0 (#4082)
With the new version of Visual Studio bringing C# 12, we can revise our logic for better readability as well as use new methods/APIs introduced in the .NET 8.0 BCL.
2023-12-03 20:13:20 -08:00

26 lines
886 B
C#

using System.Drawing;
using PKHeX.Core;
using QRCoder;
namespace PKHeX.Drawing.Misc;
public static class QREncode
{
public static Bitmap GenerateQRCode(DataMysteryGift mg) => GenerateQRCode(QRMessageUtil.GetMessage(mg));
public static Bitmap GenerateQRCode(PKM pk) => GenerateQRCode(QRMessageUtil.GetMessage(pk));
public static Bitmap GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int copies = 1)
{
byte[] data = QR7.GenerateQRData(pk7, box, slot, copies);
var msg = QRMessageUtil.GetMessage(data);
return GenerateQRCode(msg, ppm: 4);
}
private static Bitmap GenerateQRCode(string msg, int ppm = 4)
{
using var generator = new QRCodeGenerator();
using var data = generator.CreateQrCode(msg, QRCodeGenerator.ECCLevel.Q);
using var code = new QRCode(data);
return code.GetGraphic(ppm);
}
}