12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net.NetworkInformation;
- using System.Text;
- using System.Threading.Tasks;
- using QRCoder;
- using SixLabors.ImageSharp.Formats.Png;
- using SixLabors.ImageSharp.PixelFormats;
- using ZXing;
- namespace Ropin.Core.Common
- {
- public class QRCoderHelper
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static string RenderQrCode(string value, string level, string linsence, int width = 500, int height = 500)
- {
- string path;
-
- var barcodeFormat = "QR_CODE";
- var barcodeFormatType = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), barcodeFormat);
- var writer = new ZXing.ImageSharp.BarcodeWriter<Rgba32>
- {
- Format = barcodeFormatType,
- Options = new ZXing.QrCode.QrCodeEncodingOptions
- {
- DisableECI = true,
- CharacterSet = "UTF-8",
- Width = width,
- Height = height,
- Margin = 1
- }
- };
- var image = writer.WriteAsImageSharp<Rgba32>(value);
- var ms = new MemoryStream();
- image.Save(ms, new PngEncoder());
-
- var relativePath = Path.Combine("wwwroot/uploads/Files/", linsence + "/" + DateTime.Now.ToString("yyyyMM"));
- var directoryPath = Path.Combine(Directory.GetCurrentDirectory(), relativePath);
- if (!Directory.Exists(directoryPath))
- {
- Directory.CreateDirectory(directoryPath);
- }
- path = Path.Combine("/" + relativePath + "/", value + ".png");
-
- using (var fileStream = File.Create(directoryPath + "/" + value + ".png"))
- {
- ms.Seek(0, SeekOrigin.Begin);
- ms.CopyTo(fileStream);
- }
- return path;
- }
- }
- }
|