观看 David Jones,Agorus,与 Iron Suite 创造新的效益
观看 Milan Jovanović 使用 IronPDF
观看我们的团队演示产品
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 Bitmap
IRON VB CONVERTER ERROR developers@ironsoftware.com
Install-Package BarCode
IronBarCode 支持多种标准格式,从图像文件(jpeg、png 和 jpg)到更适合程序化操作的格式(例如位图),后者允许在程序中传递变量。此外,它还支持 PDF 等外部格式,使 IronBarCode 能够无缝集成到任何代码库中,并为开发人员提供处理文件格式和变量的灵活性。
除了可以读取所有文件格式的条形码外,IronBarcode 还可以作为条形码生成器,支持所有标准编码和格式,例如EAN8 、 Code128和Code39 。 设置条形码生成器只需要两行代码。 IronBarCode 的入门门槛低,并为开发人员提供了大量的自定义选项,是所有与条形码相关的场景的首选。
EAN8
Code128
Code39
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
System.Drawing
BarcodeWriter
12345
Image
Bitmap
如上所示,使用 IronBarCode 生成条形码只需要两行代码,并将其保存为文件以供以后使用。 IronBarCode 进一步扩展了这一功能,为开发者提供了大量选项,可以根据具体情况自定义条形码。
我们可以使用ResizeTo方法,并传入高度和宽度来调整条形码图像的大小。
ResizeTo
与上述类似,我们首先实例化BarcodeReader ,将文件路径传递给Read方法,并将其保存为变量以便稍后使用和操作条形码对象。 ReadPDF提供了读取 PDF 等外部格式的特定方法; 但是,对于一般的图像格式和位图,我们将使用Read 。
BarcodeReader
Read
ReadPDF
IronBarCode 允许开发人员扫描标准文件格式的条形码。 然而,在某些情况下,开发人员希望微调Read方法的行为,尤其是在以编程方式读取一批条形码文件的情况下。 这时BarcodeReaderOptions就派上用场了。 IronBarCode 允许您完全自定义诸如读取速度(使用Speed 、文件中是否预期存在多个条形码(使用ExpectedMultipleBarcodes )以及条形码类型(使用ExpectBarcodeTypes属性)等功能。 这样一来,开发人员就可以运行多个线程来并行读取多个图像中的条形码,还可以控制并行读取时使用的线程数。
BarcodeReaderOptions
Speed
ExpectedMultipleBarcodes
ExpectBarcodeTypes
以上仅是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");
Imports IronBarCode Imports 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 Private filtersToApply = New ImageFilterCollection(cacheAtEachIteration:= True) From { New SharpenFilter(), New InvertFilter(), New ContrastFilter(), New BrightnessFilter(), New AdaptiveThresholdFilter(), New BinaryThresholdFilter(), New GaussianBlurFilter(), New MedianBlurFilter(), New BilateralFilter() } Private myOptionsExample As New BarcodeReaderOptions() With { .ImageFilters = filtersToApply, .Speed = ReadingSpeed.Balanced, .ExpectMultipleBarcodes = True } ' Read with the options applied Private results As BarcodeResults = BarcodeReader.Read("screenshot.png", myOptionsExample) Private filteredImages() As AnyBitmap = results.FilterImages() ' Export intermediate image files to disk For i As Integer = 0 To filteredImages.Length - 1 filteredImages(i).SaveAs($"{i}_barcode.png") Next i ' Or results.ExportFilterImagesToDisk("filter-result.jpg")
IronBarcode 提供多种图像预处理过滤器可供选择,这些过滤器可以轻松应用于 BarcodeReaderOptions 中。 选择可能改善图像读取的过滤器,例如 锐化、二值阈值 和 对比度。 请记住,您选择它们的顺序就是应用的顺序。
可以选择保存应用每个过滤器的中间图像的数据。 这可以通过 ImageFilterCollection 的 SaveAtEachIteration 属性进行切换。
ImageFilterCollection
SaveAtEachIteration
来自代码示例的关键要点:
锐化
二值阈值
对比度
cacheAtEachIteration
true
了解更多关于IronBarcode图像校正的信息
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 PDF
Imports IronBarCode Imports 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 Dim MyBarCode As GeneratedBarcode = 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 Dim MyBarCodeImage As Image = MyBarCode.Image Dim MyBarCodeBitmap As Bitmap = MyBarCode.ToBitmap() Dim PngBytes() As Byte = MyBarCode.ToPngBinaryData() Using PdfStream As System.IO.Stream = MyBarCode.ToPdfStream() ' Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF End Using ' Save MyBarCode as an HTML file or tag MyBarCode.SaveAsHtmlFile("MyBarCode.Html") Dim ImgTagForHTML As String = MyBarCode.ToHtmlTag() Dim DataURL As String = 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, { 1, 2, 3 }, "Password123") ' Multiple pages of an encrypted PDF
在这个例子中,我们可以看到可以创建、调整大小和保存多种不同类型和格式的条形码; 甚至可能只需要一行代码。
利用我们流畅的 API,生成的条形码类可用于设置边距、调整大小和注释条形码。 然后,它们可以保存为图像,IronBarcode 会自动根据文件名假定正确的图像类型: GIF、HTML 文件、HTML 标签、JPEG、PDF、PNG、TIFF 和 Windows 位图。
我们还有StampToExistingPdfPage方法,该方法允许生成条形码并将其添加到现有的 PDF 中。 在编辑通用 PDF 文件或通过条形码向文档添加内部识别号码时,此功能非常有用。
StampToExistingPdfPage
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 formats
Imports IronBarCode Imports System Imports System.Drawing '''* STYLING GENERATED BARCODES ** ' BarcodeWriter.CreateBarcode creates a GeneratedBarcode object which allows the barcode to be styled and annotated. Private MyBarCode As GeneratedBarcode = 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 Dim FinalWidth As Integer = MyBarCode.Width Dim FinalHeight As Integer = MyBarCode.Height ' Recolor the barcode and its background MyBarCode.ChangeBackgroundColor(Color.LightGray) MyBarCode.ChangeBarCodeColor(Color.DarkSlateBlue) If Not MyBarCode.Verify() Then Console.WriteLine("Color contrast should be at least 50% or a barcode may become unreadable. Test using GeneratedBarcode.Verify()") End If ' 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. Dim qrCodeLogo As New QRCodeLogo("ironsoftware_logo.png") Dim myQRCodeWithLogo As GeneratedBarcode = 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 formats
在这个示例中,我们可以看到,条形码可以使用您选择的文本或条形码自身的值进行注释,并且可以使用目标计算机上已安装的任何字体。如果目标计算机上没有所需的字体,系统将选择一种合适的类似字体。 条形码可以调整大小,可以添加边距,条形码和背景都可以重新着色。 然后可以将它们保存为合适的格式。
在最后几行代码中,您可以看到,使用我们流畅的样式运算符,只需几行代码即可创建和设置条形码样式,类似于System.Linq 。
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();
Imports IronBarCode Private MyBarCode As GeneratedBarcode = 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 Dim ImgTag As String = MyBarCode.ToHtmlTag() ' Turn the image into a HTML/CSS Data URI. Dim DataURI As String = MyBarCode.ToDataUrl()
IronBarcode 有一个非常有用的功能,允许将条形码导出为自包含的 HTML,这样就没有关联的图像资产。 一切都包含在 HTML 文件中。
我们可以导出为HTML 文件、HTML 图像标签或数据 URI。
在此示例中:
BarcodeWriter.CreateBarcode
ToHtmlTag()
<img>
ToDataUri()
SaveAsHtmlFile()
无论是产品、集成还是授权问题,Iron 产品开发团队随时准备回答您所有问题。立即联系并与 Iron 开始对话,以便在您的项目中充分利用我们的库。
IronBarcode可以读取和生成大多数条码和QR标准,包括UPC A/E、EAN 8/13、Code 39、Code 93、Code 128、ITF、MSI、RSS 14/Expanded、Databar、CodaBar、QR、样式化QR、Data Matrix、MaxiCode、PDF417、Plessey和Aztec。结果提供条码数据、类型、页码、文本和条码图像;理想用于档案或索引系统。
IronBarcode自动预处理条码图像以提高速度和准确性。校正旋转、噪音、失真和倾斜以读取扫描或实时视频帧。多核、多线程支持用于批处理服务器应用程序。自动在单页和多页文档中找到一个或多个条码。无需复杂的API即可搜索特定条码类型或文档位置。
通过几行代码即可在几分钟内开始。专为.NET构建,作为易于使用的单个DLL;无依赖关系;支持32位和64位;适用于任何.NET语言。可以在Web、云、桌面或控制台应用程序中使用;支持移动和桌面设备。
你可以从这个链接下载软件产品。
专为QR构建, C#, .NET
保存或打印为文件或流,可为PDF、JPG、TIFF、GIF、BMP、PNG或HTML格式。设置颜色、质量、旋转、大小和文本。使用C#条码编程工具箱以及IronPDF和IronOCR的完整.NET文档库。
免费社区开发许可证。商业许可证起价$749。
C# .NET 条形码 QR
查看Frank如何使用IronBarcode读取其C# .NET条码应用程序中的扫描、照片和PDF文档中的条码...
C# .NET 条形码
Francesca分享了一些在C#或VB应用程序中写入条码到图像的技巧和窍门。了解如何写入条码以及IronBarcode为您提供的所有选项...
QR .NET C# VB
Jenny的团队每天使用IronBarcode编写成千上万个QR。查看他们关于如何充分利用IronBarcode的教程...
Iron团队在.NET软件组件市场拥有超过10年的经验。
直接与我们的开发团队交谈
简单明了的在线手册。
免费开发许可证。商业版起价 $749。
通过 NuGet 或 DLL 在几分钟内开始使用。
无需信用卡
试用表单已成功提交。您的试用密钥应在电子邮件中。如果没有,请联系我们support@ironsoftware.com
您的试用密钥应在电子邮件中。如果没有,请联系我们support@ironsoftware.com
在生产环境中测试,没有水印。在您需要的地方使用。
使用功能齐全的产品30天。几分钟内即可启动和运行。
在产品试用期间,全面访问我们的支持工程团队
我们产品及其关键功能的在线演示
获取项目特定功能建议
我们会回答您的所有问题,确保您获得所需的全部信息。(无任何承诺)。
请检查您的电子邮件以获取试用许可证密钥。
如果您没有收到电子邮件,请启动live chat或发送电子邮件至support@ironsoftware.com
预订无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
预定一次 30 分钟的个人演示。
无合约、无卡号、无任何长期承诺。
版权所有 © Iron Software 2013-2025