原創|其它|編輯:郝浩|2012-12-19 16:37:16.000|閱讀 2199 次
概述:如何對Aspose.Barcode生成的二維碼進行長寬比調整,如何隱藏較長的CodeText,如何改變CodeText字體大小以及如何生成多個MacroPdf417條碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
前面我為大家介紹了如何用 Aspose.Barcode 生成QR Code,Pdf417,Datamatrix和Aztec二維碼(查看二維碼系列教程)。今天為大家介紹二維碼的常見應用,如何對Aspose.Barcode生成的二維碼進行長寬比調整,如何隱藏較長的CodeText,如何改變CodeText字體大小以及如何生成多個MacroPdf417條碼。
Aspose.Barcode條形碼中的Aspect Ratio即是長寬比。3:2Aspect Ratio表示條形碼的寬是高的1.5倍,如下圖:
示例代碼如下:
[C#] // Create instance of BarCodeBuilder class BarCodeBuilder builder = new BarCodeBuilder("1234567890", Symbology.Pdf417); // Set Aspect Ratio to 3:2 or 1.5 builder.AspectRatio = 1.5f; // Save the barcode image to disk in PNG format builder.Save("barcode.png");
和一維碼不同,二維碼包含有大量的數據。通常打印出來的二維碼下面都會附一段可讀的CodeText文字,這段文字對二維碼的掃描是沒有影響的,所以當CodeText因為太長而不能顯示時,我們可以將CodeText隱藏,示例代碼如下:
[C#] Aspose.BarCode.BarCodeBuilder b; b = new Aspose.BarCode.BarCodeBuilder(); b.SymbologyType = Aspose.BarCode.Symbology.DataMatrix; b.CodeText = "The quick brown fox jumps over the lazy dog\n" + "The quick brown fox jumps over the lazy dog\n"; b.CodeLocation = Aspose.BarCode.CodeLocation.None; b.Save(@"c:\test_datamatrix.bmp", ImageFormat.Bmp);
如果非要保留CodeText,唯一的辦法就是將CodeText的字體調小,示例代碼如下:
[C#] Aspose.BarCode.BarCodeBuilder b; b = new Aspose.BarCode.BarCodeBuilder(); b.SymbologyType = Aspose.BarCode.Symbology.DataMatrix; b.CodeText = "The quick brown fox jumps over the lazy dog\n" + "The quick brown fox jumps over the lazy dog\n"; b.CodeTextFont = new System.Drawing.Font("Arial", 6f); b.Save(@"c:\test_datamatrix.bmp", ImageFormat.Bmp);
當有多個CodeText值或一個很大的CodeText值時,將大的值分成多個更小的CodeText值,然后生成多個MacroPdf417條碼。每個生成的條碼包含 File ID 和 Segment ID,以保證能正確識別。在下面的示例中生成了4個MacroPdf417條碼:
[C#] // create instance of BarCodeBuilder class and set symbology BarCodeBuilder builder = new BarCodeBuilder(); builder.SymbologyType = Symbology.MacroPdf417; // create array for storing multiple barcodes int nSize = 4; string[] lstCodeText = new string[] { "code-1", "code-2", "code-3", "code-last" }; string strFileID = "1"; // check the listbox for getting codetext and generating the barcodes for (int nCount = 1; nCount <= nSize; nCount++) { builder.CodeText = lstCodeText[nCount - 1]; // fileID should be same for all the generated barcodes builder.MacroPdf417FileID = int.Parse(strFileID); // assign segmentID in increasing order (1,2,3,....) builder.MacroPdf417SegmentID = nCount; // check if we reached last element yet if (nCount == nSize) builder.MacroPdf417LastSegment = true; else builder.MacroPdf417LastSegment = false; // save the barcode (fileid_segmentid.png) builder.Save(strFileID + "_" + nCount + ".png", ImageFormat.Png); Process.Start(strFileID + "_" + nCount + ".png"); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件