簡易條碼產生器

這是利用ZXing套件開發的,需要自己產生條碼的使用者,可以利用這個程式自己產生。
下載位置:https://drive.google.com/file/d/0BybxVRTRlzdLWUlBeGtKQXFKLVk/view?pref=2&pli=1
多行版本:https://drive.google.com/file/d/0BybxVRTRlzdLV1FQbmcxLUxZWDQ/view?usp=sharing

必須有.net 2.0 以上環境(Windows 7以上作業系統不需要)
解壓縮密碼(如果需要):http://radio-idea.blogspot.tw


可以自製QR碼、PDF417、code 39碼、code 128碼、Codabar碼,並且儲存成圖片檔



原始程式碼

參考套件來源:http://zxingnet.codeplex.com/
參考原文出處:http://vincecc.blogspot.tw/2013/11/c-zxing-qr-code-qr-code-generator-using.html

來源套件下載後,解壓縮,會有各種版本的資料夾

將資料夾內的檔案複製到專案資料夾內,併把DLL加入『參考』


/*Start*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;

using ZXing;
using ZXing.QrCode;
using ZXing.PDF417;
using ZXing.Rendering;
using ZXing.Common;

namespace BarcodegenWin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            cbCharset.SelectedIndex = 0;
            cbImageType.SelectedIndex = 0;
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int iWidth, iHeight;
            string sImgType, sCharset;
            iWidth = int.Parse(tbWidth.Text);
            iHeight = int.Parse(tbHeight.Text);
            sCharset = cbCharset.Text;
         
            sImgType = cbImageType.Text;
            if (sImgType == "")
            {
                MessageBox.Show("no Select Barcode Image Type");
                return;
            }
            if (sCharset == "")
            {
                MessageBox.Show("no Select text charset encoding");
                return;
            }
            try
            {
                BarcodeFormat iFormat = BarcodeFormat.QR_CODE; //default
                switch (sImgType.ToLower())
                {
                    case "qrcode":
                        iFormat = BarcodeFormat.QR_CODE;
                        break;
                    case "code39":
                        iFormat = BarcodeFormat.CODE_39;
                        break;
                    case "code128":
                        iFormat = BarcodeFormat.CODE_128;
                        break;
                    case "codabar":
                        iFormat = BarcodeFormat.CODABAR;
                        break;
                    case "pdf417":
                        iFormat = BarcodeFormat.PDF_417;
                        break;
                    default:
                        MessageBox.Show("no match Image type operate (%s)", sImgType);
                        return;
                }

                var writer = new BarcodeWriter
                {
                    Format = iFormat,
                };
                switch (sImgType.ToLower())
                {
                    case "pdf417":
                        writer.Options = new PDF417EncodingOptions
                        {
                            Height = iHeight,
                            Width = iWidth,
                            CharacterSet = sCharset
                        };
                        break;
                    case "qrcode":
                        writer.Options = new QrCodeEncodingOptions
                        {
                            Height = iHeight,
                            Width = iWidth,
                            CharacterSet = sCharset
                        };
                     
                        break;
                    default:
                        writer.Options = new EncodingOptions
                        {
                            Height = iHeight,
                            Width = iWidth
                        };
                        break;
                }
                pictureBox1.Image = writer.Write(tbText.Text); //output
            }
            catch(Exception ex){
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ImageFormat iformat = ImageFormat.Bmp;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = @"JPeg Image(*.jpg)|*.jpg|Bitmap Image(*.bmp)|*.bmp|Portable Network Graphics(*.png)|*.png";
            saveFileDialog1.Title = @"Save an Image File";
            saveFileDialog1.ShowDialog();

            if (saveFileDialog1.FileName != "")
            {
                switch (saveFileDialog1.FilterIndex)
                {
                    case 1:
                        iformat = ImageFormat.Jpeg;
                        break;
                    case 2:
                        iformat = ImageFormat.Bmp;
                        break;
                    case 3:
                        iformat = ImageFormat.Png;
                        break;
                }
                pictureBox1.Image.Save(saveFileDialog1.FileName, iformat);
            }
        }
    }
}
/*End*/


留言

Unknown寫道…
您好:
感謝分享好用的程式,
想問一下,Data Text輸入資料,是否可換行輸入?
WILDOX寫道…
Re: ALEX CHIU <5433158411130086774>
如果是程式碼的部分原則上你只要修改TextBox為多行輸入就可以。
至於現有程式,我在找時間改改
WILDOX寫道…
Re: ALEX CHIU <5433158411130086774>

頁面上方我放上了『多行版本』,請自行參考

這個網誌中的熱門文章

【研究】列印的條碼為什麼很難刷(掃描)

C# 使用 Process.Start 執行外部程式

統一發票列印小程式