2024-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.DrawingCore;
|
|
|
|
|
using System.DrawingCore.Imaging;
|
|
|
|
|
using ZXing;
|
|
|
|
|
using ZXing.Common;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DOAN.Infrastructure.Helper;
|
|
|
|
|
|
|
|
|
|
public class PrintHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印条形码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <param name="width"></param>
|
|
|
|
|
/// <param name="height"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static byte[] CreateBarCode(string message, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(message))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var w = new ZXing.OneD.Code128Writer();
|
|
|
|
|
BitMatrix b = w.encode(message, BarcodeFormat.CODE_128, width, height);
|
|
|
|
|
var zzb = new ZXing.ZKWeb.BarcodeWriter();
|
|
|
|
|
zzb.Options = new EncodingOptions()
|
|
|
|
|
{
|
2024-12-16 13:46:46 +08:00
|
|
|
Margin = 0,
|
2024-12-11 17:24:15 +08:00
|
|
|
PureBarcode = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bitmap b2 = zzb.Write(b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var ms = new System.IO.MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
b2.Save(ms, ImageFormat.Png);
|
|
|
|
|
var bytes = ms.ToArray();
|
|
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 18:31:31 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 打印二维码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <param name="width"></param>
|
|
|
|
|
/// <param name="height"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static byte[] CreateQcCode(string message, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(message))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var w = new ZXing.OneD.Code128Writer();
|
|
|
|
|
BitMatrix b = w.encode(message, BarcodeFormat.QR_CODE, width, height);
|
|
|
|
|
var zzb = new ZXing.ZKWeb.BarcodeWriter();
|
|
|
|
|
zzb.Options = new EncodingOptions()
|
|
|
|
|
{
|
|
|
|
|
Margin = 0,
|
|
|
|
|
PureBarcode = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bitmap b2 = zzb.Write(b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var ms = new System.IO.MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
b2.Save(ms, ImageFormat.Png);
|
|
|
|
|
var bytes = ms.ToArray();
|
|
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
|
}
|