ZXing(C#)との使用の詳細な例

入門

ZXingは、オープンソース、様々な形式でJavaで実装1D / 2Dバーコード画像処理ライブラリであり、他の言語のポートへのリンクを含みます。Zxingは、スキャンとデコードバーコードを完了するために、内蔵のカメラ付き携帯電話を使用して達成することができます。(Baiduの百科事典から引用)

使用

様々なフォーマットをサポートするために、一次元コード、二次元コードを生成する(例:データマトリックス、QR、Code39の、等)
様々なフォーマットをサポートするために、一次元コード、二次元コードを解析する(例:データマトリックス、QR、Code39の、等)

ソース

倉庫

 /// <summary>
        /// 解码二维码
        /// </summary>
        /// <param name="barcodeBitmap">待解码的二维码图片</param>
        /// <returns>扫码结果</returns>
        public static string DecodeQrCode(Bitmap barcodeBitmap)
        {
            BarcodeReader reader = new BarcodeReader();
            reader.Options.CharacterSet = "UTF-8";
            var result = reader.Decode(barcodeBitmap);
            return (result == null) ? null : result.Text;
        }
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="text">内容</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        public static Bitmap Generate2DBarcode(string text,int width,int height)
        {
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions()
            {
                DisableECI = true,//设置内容编码
                CharacterSet = "UTF-8",  //设置二维码的宽度和高度
                Width = width,
                Height = height,
                Margin = 1//设置二维码的边距,单位不是固定像素
            };

            writer.Options = options;
            Bitmap map = writer.Write(text);
            return map;
        }

private void Btn_Create2Dbarcode_Click(object sender, EventArgs e)
        {
            BarcodePicture.Image = null;
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start(); //  开始监视代码
             Bitmap bmap=BarcodeHelper.Generate2DBarcode(CreateBarcode.Text, 100, 100);
            stopwatch.Stop(); //  停止监视
            BarcodePicture.Image = bmap;
            TimeSpan timeSpan = stopwatch.Elapsed; //  获取总时间
            double milliseconds = timeSpan.TotalMilliseconds;  //  毫秒数 
            CreateTime.Text = "Identify Time:" + timeSpan.TotalMilliseconds + "ms";
            /* Bitmap bmp = BarcodeHelper.Generate2DBarcode("123456", 100, 100);
             //保存到磁盘文件
             bmp.Save("C:/1.bmp");
             bmp.Dispose();*/
        }

        private void Btn_Identify2Dbarcode_Click(object sender, EventArgs e)
        {
            log.Clear();
            log.AppendText("Identify Start:"+System.DateTime.Now.TimeOfDay.ToString()+"\n");
            uint a = timeGetTime();
            IdentifyBarcode.Text = BarcodeHelper.DecodeQrCode((Bitmap)BarcodePicture.Image);
            //IdentifyBarcode.Text = BarcodeHelper.DecodeQrCode(BarcodeHelper.Generate2DBarcode("123", 100, 100));
            uint b = timeGetTime();
            log.AppendText("Identify End:" + System.DateTime.Now.TimeOfDay.ToString() + "\n");
            IdentifyTime.Text = "Identify Time:" + (b - a).ToString() + "ms";
        }

業績

テストの後、生成と分析手順の最初の時間は、実用的なアプリケーションに応じて、時間が5msでの発生時間内に、非常に迅速にそして少し長くなりますが、だろう(私の判断で)初期化するために時間内に解決2msのを必要とします。
重要な点は、そのイメージです。
注:現在、唯一の2D QRバーコード生成サンプルコードを解析します。あなたは、その後のプロジェクトを参照することができますBarcodeHelper.cs

ダウンロード

マイGiteeダウンロード:https://gitee.com/PErobin/Barcode-ZXing.git
公式のGitHub住所:https://github.com/zxing/zxing

参考ブログ

紹介とZXingのメソッドパラメータ:https://www.jianshu.com/p/6607e69b1121
ZXing ZXing3.1に基づいて、フル解像度を使用して:https://blog.csdn.net/dodod2012/article/details/51315112
このブログエントリ:githubのに基づいて、導入および使用を提供https://www.cnblogs.com/hnsongbiao/p/9145285.htmlを

おすすめ

転載: www.cnblogs.com/aqyl/p/11258827.html