// 生成条形码 public static void CreateCodeTxm(string message, string gifFileName, int width, int height) { if (string.IsNullOrWhiteSpace(message)) { return; } var w = new ZXing.OneD.CodaBarWriter(); BitMatrix b = w.encode(message, BarcodeFormat.ITF, width, height); var zzb = new ZXing.ZKWeb.BarcodeWriter(); zzb.Options = new EncodingOptions() { Margin = 3, PureBarcode = true }; string dir = Path.GetDirectoryName(gifFileName); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } Bitmap b2 = zzb.Write(b); b2.Save(gifFileName, ImageFormat.Gif); b2.Dispose(); }
// 生成二维码 public static void CreateCode(string message, string gifFileName, int width = 600, int height = 600) { int heig = width; if (width > height) { heig = height; width = height; } if (string.IsNullOrWhiteSpace(message)) { return; } string dir = Path.GetDirectoryName(gifFileName); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var w = new ZXing.QrCode.QRCodeWriter(); BitMatrix b = w.encode(message, BarcodeFormat.QR_CODE, width, heig); var zzb = new ZXing.ZKWeb.BarcodeWriter(); zzb.Options = new EncodingOptions() { Margin = 0, }; Bitmap b2 = zzb.Write(b); b2.Save(gifFileName, ImageFormat.Gif); b2.Dispose(); }
/// <summary> /// 生成二维码 /// </summary> /// <param name="message"></param> /// <param name="gifFileName"></param> /// <param name="width"></param> /// <param name="height"></param> public static byte[] CreateCodeEwm(string message, int width = 400, int height = 400) { int heig = width; if (width > height) { heig = height; width = height; } if (string.IsNullOrWhiteSpace(message)) { return(null); } var w = new ZXing.QrCode.QRCodeWriter(); BitMatrix b = w.encode(message, BarcodeFormat.QR_CODE, width, heig); var zzb = new ZXing.ZKWeb.BarcodeWriter { Options = new EncodingOptions { Margin = 0 } }; Bitmap bmp = zzb.Write(b); byte[] byteArray = null; using (MemoryStream stream = new MemoryStream()) { bmp.Save(stream, ImageFormat.Png); byteArray = stream.GetBuffer(); } bmp.Dispose(); return(byteArray); }
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); string url = req.Query["url"]; ZXing.ZKWeb.BarcodeWriter barcodeWriter = new ZXing.ZKWeb.BarcodeWriter { Format = ZXing.BarcodeFormat.QR_CODE, Encoder = new QRCodeWriter(), Options = new EncodingOptions { Height = 150, Width = 150 }, Renderer = new ZXing.ZKWeb.Rendering.BitmapRenderer() }; System.DrawingCore.Bitmap qrCodeImage = barcodeWriter.Write(url); return(qrCodeImage != null ? (ActionResult) new FileContentResult(ImageToByteArray(qrCodeImage), "image/jpeg") : new BadRequestObjectResult("Please pass a name on the query string or in the request body")); }
// 生成条形码 public static Bitmap CreateCodeTxmRunBitmap(string message, int width, int height) { if (string.IsNullOrWhiteSpace(message)) { throw new Exception("MMP"); } var w = new ZXing.OneD.CodaBarWriter(); BitMatrix b = w.encode(message, BarcodeFormat.ITF, width, height); var zzb = new ZXing.ZKWeb.BarcodeWriter(); zzb.Options = new EncodingOptions() { Margin = 3, PureBarcode = true }; Bitmap b2 = zzb.Write(b); return(b2); }
/// <summary> /// 生成条形码 /// </summary> /// <param name="message"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static byte[] CreateCodeTxm(string message, int width = 500, int height = 120) { var w = new ZXing.OneD.CodaBarWriter(); var b = w.encode(message, BarcodeFormat.ITF, width, height); var zzb = new ZXing.ZKWeb.BarcodeWriter { Options = new EncodingOptions() { Margin = 3, PureBarcode = true } }; var bmp = zzb.Write(b); byte[] byteArray = null; using (MemoryStream stream = new MemoryStream()) { bmp.Save(stream, ImageFormat.Png); byteArray = stream.GetBuffer(); } bmp.Dispose(); return(byteArray); }