// 生成条形码 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 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); }