C# 制作 二维码/条形码

方法一: 使用zxing.dll制作二维码和条形码,下载zxing.dll 文件后,项目 -- 引用  右键添加
C#Code   ZXing.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;

using com.google.zxing.qrcode;
using com.google.zxing;
using com.google.zxing.common;
using ByteMatrix = com.google.zxing.common.ByteMatrix;
using EAN13Writer = com.google.zxing.oned.EAN13Writer;
using EAN8Writer = com.google.zxing.oned.EAN8Writer;
using MultiFormatWriter = com.google.zxing.MultiFormatWriter;

namespace MakeBarCode
{
    public class ZXing
    {
        
        #region 生成二维码
        /// <summary>
        ///  生成二维码
        /// </summary>
        /// <param name="data">添加需要生成二维码的字符信息</param>
        /// <returns></returns>
        public s
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
/// <summary> /// 生成条码 /// </summary> private void btnEncode_Click(object sender, EventArgs e) { errorProvider1.Clear(); int W = Convert.ToInt32(this.txtWidth.Text.Trim()); int H = Convert.ToInt32(this.txtHeight.Text.Trim()); int AddNum = Convert.ToInt32(this.tbAddNum.Text.Trim()); int SerialNo = Convert.ToInt32(this.tbSerialNO.Text.Trim()); CodeLib.AlignmentPositions Align = CodeLib.AlignmentPositions.CENTER; switch (cbBarcodeAlign.SelectedItem.ToString().Trim().ToLower()) { case "left": Align = CodeLib.AlignmentPositions.LEFT; break; case "right": Align = CodeLib.AlignmentPositions.RIGHT; break; default: Align = CodeLib.AlignmentPositions.CENTER; break; } CodeLib.TYPE type = CodeLib.TYPE.UNSPECIFIED; switch (cbEncodeType.SelectedItem.ToString().Trim()) { case "Code 128": type = CodeLib.TYPE.CODE128; break; case "Code 128-A": type = CodeLib.TYPE.CODE128A; break; case "Code 128-B": type = CodeLib.TYPE.CODE128B; break; default: MessageBox.Show("请指定编码类型。"); break; } try { if (type != CodeLib.TYPE.UNSPECIFIED) { b.IncludeLabel = this.chkGenerateLabel.Checked; b.Alignment = Align; switch (this.cbLabelLocation.SelectedItem.ToString().Trim().ToUpper()) { case "BOTTOMLEFT": b.LabelPosition = CodeLib.LabelPositions.BOTTOMLEFT; break; case "BOTTOMRIGHT": b.LabelPosition = CodeLib.LabelPositions.BOTTOMRIGHT; break; case "TOPCENTER": b.LabelPosition = CodeLib.LabelPositions.TOPCENTER; break; case "TOPLEFT": b.LabelPosition = CodeLib.LabelPositions.TOPLEFT; break; case "TOPRIGHT": b.LabelPosition = CodeLib.LabelPositions.TOPRIGHT; break; default: b.LabelPosition = CodeLib.LabelPositions.BOTTOMCENTER; break; } int SerialLen = this.tbSerialNO.Text.Trim().Length; string Barcodedata = ""; int i = 0; do { int zeroNum = SerialLen - SerialNo.ToString().Trim().Length; switch (zeroNum) { case 0: Barcodedata = this.txtData.Text.Trim() + SerialNo.ToString(); break; case 1: Barcodedata = this.txtData.Text.Trim() + SerialNo.ToString().Insert(0, "0"); break; case 2: Barcodedata = this.txtData.Text.Trim() + SerialNo.ToString().Insert(0, "00"); break; case 3: Barcodedata = this.txtData.Text.Trim() + SerialNo.ToString().Insert(0, "000"); break; default : Barcodedata = this.txtData.Text.Trim() + SerialNo.ToString().Insert(0, "0000"); break; } barcode.Image = b.Encode(type, Barcodedata.ToString(), W, H); i++; SerialNo++; this.Refresh(); Thread.Sleep(1000); //Printer(); //打印 //Thread.Sleep(500); } while (i< AddNum); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿的杂货店

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值