【小y設計】二維碼條形碼打印編輯器

條碼打印,價格標籤打印,須要對打印進行排版,因而設計了一個簡單的編輯器html

支持條碼二維碼打印進行編輯排版,支持文字、圖片、條碼、二維碼、直線,能自由拖拉,刪除,並可保存爲模版。 界面以下 (下載Demo  體驗):編輯器

左邊爲參數設置,右邊爲可視編輯區,支持自由拖拉,按Del鍵刪除層。this

首先點擊左邊最上面的紙張設置,設定紙張大小。能夠直接在下拉框中選擇經常使用的紙張大小,也能夠自定義尺寸。設置好後點擊「保存設置"按鈕,則編輯區顯示相應尺寸的紙張。而後在紙張上自由插入條碼、圖片、文字、直線。編碼

支持簡單的時間變量,好比文字內容裏插入了」{當前時間}「變量,則當觸發打印操做的時候,再取當前時間,並替換該變量:spa

 

程序源碼截圖:設計

 

關鍵技術點:3d

1.實現如Photoshop相似的圖層概念code

  剛開始準備使用GDI+繪製圖層,而後用鼠標定位當前選中的對象,後來改進成用自定義控件實現,在控件上畫對象,只須要對控件添加統一的鼠標事件就能夠實現圖層移動、刪除等操做。orm

2.繪製條碼、二維碼,涉及中文問題、條碼編碼方式問題htm

使用的開源二維碼庫zxing,我以前的其餘文章也有詳細介紹,不贅述。

 //條碼類型
            BarcodeFormat myBarcodeFormat;
            EncodingOptions myEncoding;
            if (this.CodeType == 1) //二維碼
            {
                myBarcodeFormat = BarcodeFormat.QR_CODE;
                myEncoding = new QrCodeEncodingOptions()
                {
                    Height = this.Height,
                    Width = this.Width,
                    Margin = 0,
                    CharacterSet="UTF-8",
                    PureBarcode = !this.IsShowText
                };
            }
            else //條形碼
            {
                myBarcodeFormat = BarcodeFormat.CODE_128;
                myEncoding = new EncodingOptions()
                {
                    Height = this.Height,
                    Width = this.Width,
                    Margin = 0,
                    PureBarcode = !this.IsShowText
                };
            }
            //生成條碼QrCodeEncodingOptions
            BarcodeWriter writer = new BarcodeWriter
            {
                Format = myBarcodeFormat,
                Options = myEncoding,
                Renderer = (IBarcodeRenderer<Bitmap>)Activator.CreateInstance(typeof(BitmapRenderer))
            };
            
            Bitmap  barImg= writer.Write(this.Content);

這裏強調一點是,使用UTF-8編碼防止中文亂碼。其二,條碼編碼方式使用Code_128,支持任意ascii碼。

相關文章
相關標籤/搜索