在生產環境中進行無水印測試。
無論在何處需要,它都能正常運作。
獲得 30 天完整功能產品試用期。
幾分鐘就能安裝運作。
產品試用期間,您可以隨時聯絡我們的支援工程團隊。
using IronBarCode;
using System.Drawing;
// Reading a barcode is easy with IronBarcode!
var resultFromFile = BarcodeReader.Read(@"file/barcode.png"); // From a file
var resultFromBitMap = BarcodeReader.Read(new Bitmap("barcode.bmp")); // From a bitmap
var resultFromImage = BarcodeReader.Read(Image.FromFile("barcode.jpg")); // From an image
var resultFromPdf = BarcodeReader.ReadPdf(@"file/mydocument.pdf"); // From PDF use ReadPdf
// To configure and fine-tune barcode reading, utilize the BarcodeReaderOptions class
var myOptionsExample = new BarcodeReaderOptions
{
// Choose a reading speed from: Faster, Balanced, Detailed, ExtremeDetail
// There is a tradeoff in performance as more detail is set
Speed = ReadingSpeed.Balanced,
// Reader will stop scanning once a single barcode is found (if set to false)
ExpectMultipleBarcodes = true,
// By default, all barcode formats are scanned for
// Specifying a subset of barcode types to search for would improve performance
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
// Utilize multiple threads to read barcodes from multiple images in parallel
Multithreaded = true,
// Maximum threads for parallelized barcode reading
// Default is 4
MaxParallelThreads = 2,
// The area of each image frame in which to scan for barcodes
// Specifying a crop area will significantly improve performance and avoid noisy parts of the image
CropArea = new Rectangle(),
// Special setting for Code39 barcodes
// If a Code39 barcode is detected, try to read with both the base and extended ASCII character sets
UseCode39ExtendedMode = true
};
// Read with the options applied
var results = BarcodeReader.Read("barcode.png", myOptionsExample);
// Create a barcode with one line of code
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
// After creating a barcode, we may choose to resize
myBarcode.ResizeTo(400, 100);
// Save our newly-created barcode as an image
myBarcode.SaveAsImage("EAN8.jpeg");
Image myBarcodeImage = myBarcode.Image; // Can be used as Image
Bitmap myBarcodeBitmap = myBarcode.ToBitmap(); // Can be used as BitmapInstall-Package BarCode
IronBarCode 支援多種標準格式,從映像檔(jpeg、png 和 jpg)到更適合程式化操作的格式(例如點陣圖),後者允許在程式中傳遞變數。此外,它還支援 PDF 等外部格式,使 IronBarCode 能夠無縫整合到任何程式碼庫中,並為開發人員提供處理文件格式和變數的靈活性。
除了可以讀取所有檔案格式的條碼外,IronBarcode 還可以作為條碼產生器,支援所有標準編碼和格式,例如EAN8 、 Code128和Code39 。 設定條碼產生器只需要兩行程式碼。 IronBarCode 的入門門檻低,並為開發人員提供了大量的自訂選項,是所有與條碼相關的場景的首選。
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeEncoding.EAN8);Image myBarcodeImage = myBarcode.ToImage();myBarcode.ResizeTo(400,100);。var resultFromFile = BarcodeReader.Read(@"file/barcode.png");。var myOptionsExample = new BarcodeReaderOptions { /* Options */ };我們首先導入必要的函式庫,如IronBarCode和System.Drawing ,並實例化BarcodeWriter來建立一個字串值為12345 、格式為EAN8的條碼。 然後我們將生成的條碼以所需格式儲存為圖像。 IronBarCode 支援將條碼建立為Image和Bitmap ,因此有多種選擇。
如上所示,使用 IronBarCode 產生條碼只需要兩行程式碼,並將其儲存為檔案以供以後使用。 IronBarCode 進一步擴展了這項功能,為開發者提供了大量選項,可以根據具體情況自訂條碼。
我們可以使用ResizeTo方法,並傳入高度和寬度來調整條碼圖像的大小。
與上述類似,我們首先實例化BarcodeReader ,將檔案路徑傳遞給Read方法,並將其儲存為變數以便稍後使用和操作條碼物件。 ReadPDF提供了讀取外部格式(例如 PDF)的指定方法; 但是,對於一般的影像格式和點陣圖,我們將使用Read 。
IronBarCode 允許開發人員掃描標準檔案格式的條碼。 然而,在某些情況下,開發人員希望微調Read方法的行為,尤其是在以程式設計方式讀取一批條碼檔案的情況下。 This is where BarcodeReaderOptions comes in. IronBarCode lets you fully customize things such as the speed at which it reads with Speed, whether multiple barcodes are expected in the file with ExpectedMultipleBarcodes, and what kind of barcodes they are with the property ExpectBarcodeTypes. 這允許開發人員執行多個線程,從多個影像中平行讀取 BarCode,以及在進行平行讀取時控制使用的線程數。
以上僅為IronBarCode強大功能的部分體現。 完整清單請參閱此處的文件。
using IronBarCode;
using IronSoftware.Drawing;
// Choose which filters are to be applied (in order)
// Set cacheAtEachIteration = true to save the intermediate image data after each filter is applied
var filtersToApply = new ImageFilterCollection(cacheAtEachIteration: true) {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter(),
new BrightnessFilter(),
new AdaptiveThresholdFilter(),
new BinaryThresholdFilter(),
new GaussianBlurFilter(),
new MedianBlurFilter(),
new BilateralFilter()
};
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Set chosen filters in BarcodeReaderOptions
ImageFilters = filtersToApply,
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
};
// Read with the options applied
BarcodeResults results = BarcodeReader.Read("screenshot.png", myOptionsExample);
AnyBitmap[] filteredImages = results.FilterImages();
// Export intermediate image files to disk
for (int i = 0 ; i < filteredImages.Length ; i++)
filteredImages[i].SaveAs($"{i}_barcode.png");
// Or
results.ExportFilterImagesToDisk("filter-result.jpg");Install-Package BarCode
IronBarcode 提供了許多影像預處理濾鏡供選擇,這些濾鏡可以輕鬆地在BarcodeReaderOptions中套用。 選擇可改善影像讀取的濾鏡,例如 Sharpen、Binary Threshold,以及 Contrast。 請記住,您選擇它們的順序是它們實際應用的順序。
可以選擇保存應用每個濾波器後的中間影像的影像資料。 這可以透過ImageFilterCollection的SaveAtEachIteration屬性來切換。
精選程式碼範例重點:
BarcodeReaderOptions實例,並為其配置各種影像濾鏡: Sharpen 、 Binary Threshold和Contrast 。cacheAtEachIteration設為true ,該程式庫會在每次應用濾鏡後保存中間影像,這對於偵錯和分析非常有用。 最後,我們從圖像中讀取條碼,並將條碼類型和值列印到控制台。using IronBarCode;
using System.Drawing;
/*** CREATING BARCODE IMAGES ***/
// Create and save a barcode in a single line of code
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg");
/***** IN-DEPTH BARCODE CREATION OPTIONS *****/
// BarcodeWriter.CreateBarcode creates a GeneratedBarcode which can be styled and exported as an Image object or file
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("Any Number, String or Binary Value", BarcodeWriterEncoding.Code128);
// Style the Barcode in a fluent LINQ-style fashion
MyBarCode.ResizeTo(300, 150).SetMargins(20).AddAnnotationTextAboveBarcode("Example EAN8 Barcode").AddBarcodeValueTextBelowBarcode();
MyBarCode.ChangeBackgroundColor(Color.LightGoldenrodYellow);
// Save the barcode as an image file
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
// Save the barcode as a .NET native object
Image MyBarCodeImage = MyBarCode.Image;
Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
byte[] PngBytes = MyBarCode.ToPngBinaryData();
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream())
{
// Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}
// Save MyBarCode as an HTML file or tag
MyBarCode.SaveAsHtmlFile("MyBarCode.Html");
string ImgTagForHTML = MyBarCode.ToHtmlTag();
string DataURL = MyBarCode.ToDataUrl();
// Save MyBarCode to a new PDF, or stamp it in any position on any page(s) of an existing document
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1); // Position (200, 50) on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, new[] { 1, 2, 3 }, "Password123"); // Multiple pages of an encrypted PDFInstall-Package BarCode
在這個例子中,我們可以看到可以建立、調整大小和保存多種不同類型和格式的條碼; 甚至可能只需要一行程式碼。
利用我們流暢的 API,產生的條碼類別可用於設定邊距、調整大小和註解條碼。 然後,它們可以儲存為影像,IronBarcode 會自動根據檔案名稱假定正確的影像類型: GIF、HTML 檔案、HTML 標籤、JPEG、PDF、PNG、TIFF 和 Windows 位圖。
We also have the StampToExistingPdfPage method, which allows a barcode to be generated and stamped onto an existing PDF. 在編輯通用 PDF 文件或透過條碼向文件添加內部識別號碼時,此功能非常有用。
using IronBarCode;
using System;
using System.Drawing;
/*** STYLING GENERATED BARCODES ***/
// BarcodeWriter.CreateBarcode creates a GeneratedBarcode object which allows the barcode to be styled and annotated.
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("Iron Software", BarcodeWriterEncoding.QRCode);
// Any text (or commonly, the value of the barcode) can be added to the image in a default or specified font.
// Text positions are automatically centered, above or below. Fonts that are too large for a given image are automatically scaled down.
MyBarCode.AddBarcodeValueTextBelowBarcode();
MyBarCode.AddAnnotationTextAboveBarcode("This is My Barcode", new Font(new FontFamily("Arial"), 12, FontStyle.Regular, GraphicsUnit.Pixel), Color.DarkSlateBlue);
// Resize, add margins and check final image dimensions
MyBarCode.ResizeTo(300, 300); // Resize in pixels
MyBarCode.SetMargins(0, 20, 0, 20); // Set margins in pixels
int FinalWidth = MyBarCode.Width;
int FinalHeight = MyBarCode.Height;
// Recolor the barcode and its background
MyBarCode.ChangeBackgroundColor(Color.LightGray);
MyBarCode.ChangeBarCodeColor(Color.DarkSlateBlue);
if (!MyBarCode.Verify())
{
Console.WriteLine("Color contrast should be at least 50% or a barcode may become unreadable. Test using GeneratedBarcode.Verify()");
}
// Finally, save the result
MyBarCode.SaveAsHtmlFile("StyledBarcode.html");
/*** STYLING BARCODES IN A SINGLE LINQ-STYLE EXPRESSION ***/
// Create a barcode in one line of code
BarcodeWriter.CreateBarcode("https://ironsoftware.com", BarcodeWriterEncoding.Aztec).ResizeTo(250, 250).SetMargins(10).AddBarcodeValueTextAboveBarcode().SaveAsImage("StyledBarcode.png");
/*** STYLING QR CODES WITH LOGO IMAGES OR BRANDING ***/
// Use the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode
// Logo will automatically be sized appropriately and snapped to the QR grid.
var qrCodeLogo = new QRCodeLogo("ironsoftware_logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
myQRCodeWithLogo.SaveAsPng("QRWithLogo.Png").SaveAsPdf("MyVerifiedQR.html"); // Save as 2 different formatsInstall-Package BarCode
在這個範例中,我們可以看到,條碼可以使用您選擇的文字或條碼本身的值進行註釋,並且可以使用目標電腦上已安裝的任何字型。如果目標電腦上沒有所需的字體,系統將選擇合適的類似字體。 條碼可以調整大小,可以添加邊距,條碼和背景都可以重新著色。 然後可以將它們儲存為合適的格式。
在最後幾行程式碼中,您可以看到,使用我們流暢的樣式運算符,只需幾行程式碼即可建立和設定條碼樣式,類似於System.Linq 。
using IronBarCode;
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);
// Save as a stand-alone HTML file without any image assets
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
// Save as a stand-alone HTML image tag which can be served in HTML files, ASPX or MVC Views. No image assets required, the tag embeds the entire image in its source content
string ImgTag = MyBarCode.ToHtmlTag();
// Turn the image into a HTML/CSS Data URI.
string DataURI = MyBarCode.ToDataUrl();Install-Package BarCode
IronBarcode 有一個非常有用的功能,可以將條碼匯出為獨立的 HTML,這樣它就沒有關聯的圖像資源。 所有內容都包含在HTML檔案中。
我們可以將內容匯出為HTML 檔案、 HTML 圖片標籤或資料 URI 。
在這個範例中
BarcodeWriter.CreateBarcode來建立條碼,指定輸入資料和編碼類型。ToHtmlTag()產生 HTML<img>可嵌入網頁的標籤。ToDataUri()建立一個資料 URI 字串,該字串可用作資料來源<img>標籤或幾乎任何需要圖片 URL 的地方。SaveAsHtmlFile()將條碼保存為獨立的 HTML 文件,其中包含所有圖像數據,使其便於攜帶和共享。
IronBarcode 可讀取和產生大多數條碼和二維碼標準,包括 UPC A/E、EAN 8/13、Code 39、Code 93、Code 128、ITF、MSI、RSS 14/Expanded、Databar、CodaBar、QR、Styled QR、Mtec、Maxi、Code、417、CodeA、Ptec.結果提供條碼資料、類型、頁碼、文字和條碼圖像;非常適合用於歸檔或索引系統。
查看完整功能列表
IronBarcode 可自動預處理條碼影像,進而提高速度和準確性。它能校正旋轉、雜訊、失真和傾斜,以讀取掃描影像或即時視訊幀。支援多核心多線程,適用於批量處理伺服器應用程式。可自動在單頁和多頁文件中尋找一個或多個條碼。無需複雜的 API,即可搜尋特定條碼類型或文件位置。
了解更多儲存或列印到檔案或串流,支援 PDF、JPG、TIFF、GIF、BMP、PNG 或 HTML 格式。可設定顏色、品質、旋轉角度、大小和文字。結合 C# 條碼程式設計工具箱、IronPDF 和 IronOCR,即可建立完整的 .NET 文件庫。
了解更多






C# 。網 條碼 QR 圖碼

看看 Frank 如何在他的 C# .NET 條碼應用程式中使用 IronBarcode 讀取掃描件、照片和 PDF 文件中的條碼…
查看弗蘭克的條碼讀取教程
C# 。網 條碼

Francesca 分享了一些在 C# 或 VB 應用程式中將條碼寫入圖像的技巧和訣竅。了解如何使用 IronBarcode 編寫條碼以及所有可用的選項…
請參閱 Francesca 的條碼教學
QR 圖碼 。網 C# VB

Jenny 的團隊使用 IronBarcode 每天產生數千個二維碼。請觀看他們的教學課程,了解如何充分利用 IronBarcode…
Jenny團隊的二維碼編寫教學


Iron 團隊在 .NET 軟體組件市場擁有超過 10 年的經驗。







