翻譯|使用教程|編輯:黃竹雯|2019-01-07 10:15:11.000|閱讀 373 次
概述:本系列教程會解答您在使用條形碼生成控件TBarCode SDK產品時遇到的絕大部分疑惑。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TBarCode SDK是一款可以在任意應用程序和打印機下生成和打印所有條碼的條碼軟件組件。TBarCode SDK對于Microsoft® Office 用戶以及軟件開發者提供條碼打印。使用此款條碼軟件組件你可以生成和打印所有用于工業和商業條碼符號。
首先以默認的Pixel格式生成條形碼(Format32bppArgb):
System.Drawing.Size optimalSize = myBarcode.CalculateOptimalBitmapSize(null, 2, 2); myBarcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); Bitmap barcodeImage = myBarcode.DrawBitmap();
然后將其轉換為你需要的Pixel格式的位圖:
Bitmap converted = barcodeImage.Clone (new Rectangle(0, 0, barcodeImage.Width, barcodeImage.Height), PixelFormat.Format4bppIndexed); // MessageBox.Show(converted.PixelFormat.ToString());
即使你對二進制數據使用轉義序列,編碼器也將使用Codepage Conversion(代碼頁轉換)(例如:\x88根據需要在Data Matrix中輸出不同的值)。
解決方案:
在部署ASP.NET項目到你的IIS Web服務器之后,會出現System.BadImageFormatException(嘗試加載格式不正確的程序)。在開發過程中沒有這樣的問題。
原因:Visual Studio是一個32位應用程序,開發服務器通常以32位進程運行。因此,32位版本的TECIT.TBarCode.DLL已嵌入到你的項目中,在./bin文件夾中。但是你的IIS以64位進程運行,所以會加載錯誤的格式。
方法1:部署64位版本的程序集
使用C:\Program Files\Common Files\TEC-IT\TBarCode\[version]文件夾中的版本(這是x64版本)。使用該版本交換目標系統上的../bin/TECIT.TBarCode.dll文件。
方法2:讓GAC來完成這個工作
從bin文件夾中完全刪除TECIT.TBarCode.dll。在這種情況下,將加載來自全局程序集緩存(GAC)的TECIT.TBarCode.dll。公共語言運行庫自動加載正確的版本,因為GAC同時包含32和64位版本。
前置條件:必須在目標服務器上執行TBarCode SDK的設置,安裝程序會為你安裝GAC中的DLL。
如果你沒有立即看到效果,請重新啟動應用程序池或在命令行上執行“iisreset”(注意,這會重新啟動ALL,會話將丟失)。
以下示例代碼可在ASP.NET中生成Code 39位圖。
//Code 39 Barcode barcode = new Barcode(); barcode.Data = "10030000007611107871900002199908"; barcode.BarcodeType = BarcodeType.Code39; // with dpi = 100 we get 1 Pixel = 0.254 mms barcode.Dpi = 100; // bar code size should adapt to bounding rectangle barcode.SizeMode = SizeMode.FitToBoundingRectangle; // set default size of symbol (define the default height) barcode.BoundingRectangle = new Rectangle(0, 0, 254, 100 /* = 1 inch */); // now calculate optimal bitmap size for the bar code Size optimalSize = barcode.CalculateOptimalBitmapSize(null, 1, 1); // update rectangle to optimized size barcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); barcode.Draw(filename, ImageType.Jpg);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn