原創(chuàng)|其它|編輯:郝浩|2012-12-19 16:37:16.000|閱讀 2199 次
概述:如何對(duì)Aspose.Barcode生成的二維碼進(jìn)行長寬比調(diào)整,如何隱藏較長的CodeText,如何改變CodeText字體大小以及如何生成多個(gè)MacroPdf417條碼。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
前面我為大家介紹了如何用 Aspose.Barcode 生成QR Code,Pdf417,Datamatrix和Aztec二維碼(查看二維碼系列教程)。今天為大家介紹二維碼的常見應(yīng)用,如何對(duì)Aspose.Barcode生成的二維碼進(jìn)行長寬比調(diào)整,如何隱藏較長的CodeText,如何改變CodeText字體大小以及如何生成多個(gè)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");
和一維碼不同,二維碼包含有大量的數(shù)據(jù)。通常打印出來的二維碼下面都會(huì)附一段可讀的CodeText文字,這段文字對(duì)二維碼的掃描是沒有影響的,所以當(dāng)CodeText因?yàn)樘L而不能顯示時(shí),我們可以將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的字體調(diào)小,示例代碼如下:
[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);
當(dāng)有多個(gè)CodeText值或一個(gè)很大的CodeText值時(shí),將大的值分成多個(gè)更小的CodeText值,然后生成多個(gè)MacroPdf417條碼。每個(gè)生成的條碼包含 File ID 和 Segment ID,以保證能正確識(shí)別。在下面的示例中生成了4個(gè)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"); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件