在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
using IronBarCode;
using System.Drawing;
// Creating a barcode is as simple as:
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
// And save our barcode as in image:
myBarcode.SaveAsImage("EAN8.jpeg");
Image myBarcodeImage = myBarcode.Image; // Can be used as Image
Bitmap myBarcodeBitmap = myBarcode.ToBitmap(); // Can be used as Bitmap
// 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
// After creating a barcode, we may choose to resize and save which is easily done with:
var myNewBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);
myNewBarcode.ResizeTo(400, 100);
myNewBarcode.SaveAsImage("myBarcodeResized.jpeg");
// To set more options and optimization with your Barcode Reading,
// Please utilize the BarcodeReaderOptions paramter of read:
var myOptionsExample = new BarcodeReaderOptions
{
// Choose a 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 barcode is found, unless set to true
ExpectMultipleBarcodes = true,
// By default, all barcode formats are scanned for.
// Specifying one or more, performance will increase.
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
// Utilizes multiple threads to reads barcodes from multiple images in parallel.
Multithreaded = true,
// Maximum threads for parallel. Default is 4
MaxParallelThreads = 2,
// The area of each image frame in which to scan for barcodes.
// Will improve performance significantly and avoid unwanted results and avoid noisy parts of the image.
CropArea = new Rectangle(),
// Special Setting for Code39 Barcodes.
// If a Code39 barcode is detected. Try to use extended mode for the full ASCII Character Set
UseCode39ExtendedMode = true
};
// And, apply:
var results = BarcodeReader.Read("barcode.png", myOptionsExample);
Imports IronBarCode
Imports System.Drawing
' Creating a barcode is as simple as:
Private myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
' And save our barcode as in image:
myBarcode.SaveAsImage("EAN8.jpeg")
Dim myBarcodeImage As Image = myBarcode.Image ' Can be used as Image
Dim myBarcodeBitmap As Bitmap = myBarcode.ToBitmap() ' Can be used as Bitmap
' Reading a barcode is easy with IronBarcode:
Dim resultFromFile = BarcodeReader.Read("file/barcode.png") ' From a file
Dim resultFromBitMap = BarcodeReader.Read(New Bitmap("barcode.bmp")) ' From a bitmap
Dim resultFromImage = BarcodeReader.Read(Image.FromFile("barcode.jpg")) ' From an image
Dim resultFromPdf = BarcodeReader.ReadPdf("file/mydocument.pdf") ' From PDF use ReadPdf
' After creating a barcode, we may choose to resize and save which is easily done with:
Dim myNewBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
myNewBarcode.ResizeTo(400, 100)
myNewBarcode.SaveAsImage("myBarcodeResized.jpeg")
' To set more options and optimization with your Barcode Reading,
' Please utilize the BarcodeReaderOptions paramter of read:
Dim myOptionsExample = New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
.Multithreaded = True,
.MaxParallelThreads = 2,
.CropArea = New Rectangle(),
.UseCode39ExtendedMode = True
}
' And, apply:
Dim results = BarcodeReader.Read("barcode.png", myOptionsExample)
BarcodeWriter.CreateBarcode类可用于根据字符串、数字或二进制数据创建条形码和 QR 码,并将其编码为适当的格式。然后,我们可以使用
SaveAsImage()方法导出为图像,或使用其他简单的保存方法保存为 PDF、HTML、System.Drawing.Image
、流或Bitmap
对象。
同样,我们可以使用 BarcodeReader
类读取条形码。最简单的方法是 BarcodeReader.Read
方法,如上图所示。
请注意 "BarcodeReaderOptions"(条码阅读器选项)中设置的各种选项,这些选项允许您自定义读取速度、读取强度、在读取到一个条码后停止扫描以节省时间、指定要搜索的特定条码类型以及使用多线程等其他自定义选项。
using IronBarCode;
using IronSoftware.Drawing;
using System.Linq;
// Choose which filters are to be applied (in order);
var filtersToApply = new ImageFilterCollection() {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter(),
new BrightnessFilter(),
new AdaptiveThresholdFilter(),
new BinaryThresholdFilter()
};
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Set chosen filters in BarcodeReaderOptions:
ImageFilters = filtersToApply,
// Other Barcode Reader Options:
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
};
// And, apply with a Read:
BarcodeResults results = BarcodeReader.Read("screenshot.png", myOptionsExample);
AnyBitmap[] filteredImages = results.FilterImages();
// Export file 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
Imports System.Linq
' Choose which filters are to be applied (in order);
Private filtersToApply = New ImageFilterCollection() From {
New SharpenFilter(),
New InvertFilter(),
New ContrastFilter(),
New BrightnessFilter(),
New AdaptiveThresholdFilter(),
New BinaryThresholdFilter()
}
Private myOptionsExample As New BarcodeReaderOptions() With {
.ImageFilters = filtersToApply,
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True
}
' And, apply with a Read:
Private results As BarcodeResults = BarcodeReader.Read("screenshot.png", myOptionsExample)
Private filteredImages() As AnyBitmap = results.FilterImages()
' Export file 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 有许多过滤器可供选择,并可在条码阅读器选项中轻松应用。选择可提高图像读取效率的过滤器,如锐化、反转、反转、反转、反转、反转、反转、反转、反转、反转、反转、反转、反转。 (颜色)和对比度。请记住,您选择的顺序就是它们的应用顺序。
using IronBarCode;
using System.Drawing;
/*** CREATING BARCODE IMAGES ***/
// Shorthand:: 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 styles 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 MyBarCode 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 MyBarCode as a .NET native objects
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 HTML files and tags
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 200x50 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 **
' Shorthand:: 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 styles 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 MyBarCode 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 MyBarCode as a .NET native objects
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 HTML files and tags
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 200x50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, { 1, 2, 3 }, "Password123") ' multiple pages of an encrypted PDF
在这个例子中,我们可以看到许多不同类型和格式的条形码都可以创建、调整大小和保存,甚至可能只需一行代码。
使用 Fluent API,生成的条形码类可用于设置边距、调整大小和注释条形码。然后,它们可以保存为图像,IronOCR 会根据文件名自动生成正确的图像类型: GIF、HTML 文件、HTML 标记、JPEG、PDF、PNG、TIFF 和 Windows 位图。
我们还有 "StampToExistingPdfPage "方法,该方法允许生成条形码并在现有 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); // pixels
MyBarCode.SetMargins(0, 20, 0, 20);
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 ***/
// Fluent API
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 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) ' pixels
MyBarCode.SetMargins(0, 20, 0, 20)
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 **
' Fluent API
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 formats
在这个示例中,我们可以看到条形码可以使用目标计算机上安装的任何字体来注释您选择的文本或条形码本身的值。如果没有可用的字体,则会选择适当的类似字体。条形码的大小可以调整,可以添加页边距,条形码和背景都可以重新着色。然后可以将它们保存为适当的格式。
在最后几行代码中,您可以看到使用我们的流畅样式操作符,只需几行代码就可以创建和样式化一个条形码,类似于 System.Linq
。
using IronBarCode;
/*** EXPORTING BARCODES AS HTML FILES OR TAGS ***/
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);
// Save as a stand-alone HTML file with no image assets required
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 Src contents
string ImgTag = MyBarCode.ToHtmlTag();
// Turn the image into an Html/CSS Data URI. https://en.wikipedia.org/wiki/Data_URI_scheme
string DataURI = MyBarCode.ToDataUrl();
Imports IronBarCode
'''* EXPORTING BARCODES AS HTML FILES OR TAGS **
Private MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128)
' Save as a stand-alone HTML file with no image assets required
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 Src contents
Dim ImgTag As String = MyBarCode.ToHtmlTag()
' Turn the image into an Html/CSS Data URI. https://en.wikipedia.org/wiki/Data_URI_scheme
Dim DataURI As String = MyBarCode.ToDataUrl()
Iron Barcode 有一个非常有用的功能,可将条形码导出为自包含的 HTML,这样就没有相关的图像资产。所有内容都包含在 HTML 文件中。
我们可以导出为HTML 文件、HTML 图像标记或数据 URI。
IronBarcode .NET 条码库可以读取 BarcodeEncoding 枚举中的任何类型的条码。它可以在 .NET Core、.NET Standard 和 .NET Framework 中识别条码。
为了节省时间并提高库存工作流程的效率,IronBarcode建议使用一维(1D)或线性条形码,包括传统和已确立的条形码类型,如UPC和EAN码。全球各地的销售点服务通常使用UPC(通用商品代码)条形码(包括其变种UPC-A和UPC-E)。这使目标消费者受益,因为它使在仓库和结账时更容易识别和跟踪产品特征。UPCA的内容仅限于12到13位数字,而UPCE支持8到13位数字的内容。
像UPC一样,欧洲市场使用EAN条形码给消费品贴标签以进行销售点扫描。它的变体包括默认的EAN-13,而EAN-8则用于包装空间有限的产品,如糖果。除了它们的灵活性之外,作为一种高密度条形码,EAN-13还能够紧凑地编码更大的数据集。
一维条形码并不止于此。
汽车和国防行业使用Code 39条形码。其名称说明了它能够编码39个字符(现已修订为43个)。类似地,Code 128字符集具有高数据密度。继续在物流方面,包装行业更喜欢使用ITF(交错2 of 5)条形码来标记包装材料,如瓦楞纸板,因为它们具有高打印容差。而MSI条形码则更适合产品识别和库存管理。
制药行业使用制药二进制代码。RSS 14(减少空间符号)和Databar条形码是1D和2D条形码的混合。它是标记小物件的医疗保健最爱。类似于Code 128条形码,Codabar也是物流和医疗保健的最爱。它无需计算机工作,可以从点阵打印机输出中读取。
二维条码包括Aztec, Data Matrix, Data Bar, IntelligentMail, Maxicode, QR code。在不同的行业中使用,Aztec在运输行业的票据和登机牌上使用,具有在低分辨率下的可读性。虽然IntelligentMail仅限于美国邮件的特定用途,但Maxicode用于标准化货物追踪。
最广为人知的条形码是二维码。由于其灵活性、容错能力、可读性以及对各种数据的支持,如数字、字母数字、字节/二进制和汉字,它在B2B到B2C之间有着广泛的用途。
一旦确定类型,IronBarcode - 领先的条形码生成器将接管!
在 .NET 中读取条形码类型,现在使用 IronBarcode 的多功能、高级和高效库变得轻而易举。
由于IronBarcode能够创建、调整大小和保存各种条形码类型和格式,没有理由不立即开始使用它!
使用Fluent API,通过生成的条码类设置边距、调整大小和注释条码。然后使用IronOCR自动根据文件名假定正确的图像类型保存为图像。无论是GIF、HTML文件、HTML标签、JPEG、PNG、TIFF还是Windows位图。
StampToExistingPdfPage方法允许生成条形码并将其盖在现有的PDF上。这在编辑通用PDF或通过条形码向文档添加内部识别号码时非常有用。
立即联系24/7真人支持。无论您有问题还是需要项目支持;从我们的30天试用密钥开始,从我们易于理解的英语广泛文档资源中受益,或者从我们起价$749的终身许可中受益。
C# .NET 条形码 QR
C# .NET 条形码
Francesca 分享了一些在 C# 或 VB 应用程序中将条形码写入图像的技巧和窍门。了解如何编写条形码以及使用 IronBarcode 可用的所有选项...
查看弗朗西斯卡的条形码教程QR .NET C# VB
Jenny的团队每天使用IronBarcode编写成千上万个二维码。查看他们的教程,了解如何充分利用IronBarcode ...
Jenny团队的QR编写教程Iron的团队在.NET软件组件市场拥有超过10年的经验。