- image
- RasterImage referencing the bitmap that holds the image data.
- searchRectangle
- LeadRect that contains the search area for the barcodes. Pass LeadRect.Empty to search the whole image. If this parameter is LeadRect.Empty and the image does not have a region, the entire image will be searched. If this parameter is LeadRect.Empty and the image does have a region, only the region will be searched.
- searchType
- Type of barcode for which to search. You can combine values when appropriate among the same group values, by using a bitwise OR (|).
- units
- Unit of measurement.
- flags
- Processing options. values can be combined when appropriate, by using a bitwise OR (|). Pass BarcodeReadFlags.None to get the default.
- multipleMaxCount
- Specifies the maximum number of barcodes to search. Pass 0 to read all barcodes in a specified search area.
- code1d
- Barcode1d class containing linear barcode options to be read.
- codePdf
- BarcodeReadPdf class containing PDF417 and MicroPDF417 barcode options to be read.
- codeColor
- BarcodeColor class containing bar and space colors to be read.
Visual Basic (Declaration) | |
---|---|
Public Function Read( _ ByVal image As RasterImage, _ ByVal searchRectangle As LeadRect, _ ByVal searchType As BarcodeSearchTypeFlags, _ ByVal units As BarcodeUnit, _ ByVal flags As BarcodeReadFlags, _ ByVal multipleMaxCount As Integer, _ ByVal code1d As Barcode1d, _ ByVal codePdf As BarcodeReadPdf, _ ByVal codeColor As BarcodeColor _ ) As RasterCollection(Of BarcodeData) |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As BarcodeEngine Dim image As RasterImage Dim searchRectangle As LeadRect Dim searchType As BarcodeSearchTypeFlags Dim units As BarcodeUnit Dim flags As BarcodeReadFlags Dim multipleMaxCount As Integer Dim code1d As Barcode1d Dim codePdf As BarcodeReadPdf Dim codeColor As BarcodeColor Dim value As RasterCollection(Of BarcodeData) value = instance.Read(image, searchRectangle, searchType, units, flags, multipleMaxCount, code1d, codePdf, codeColor) |
Parameters
- image
- RasterImage referencing the bitmap that holds the image data.
- searchRectangle
- LeadRect that contains the search area for the barcodes. Pass LeadRect.Empty to search the whole image. If this parameter is LeadRect.Empty and the image does not have a region, the entire image will be searched. If this parameter is LeadRect.Empty and the image does have a region, only the region will be searched.
- searchType
- Type of barcode for which to search. You can combine values when appropriate among the same group values, by using a bitwise OR (|).
- units
- Unit of measurement.
- flags
- Processing options. values can be combined when appropriate, by using a bitwise OR (|). Pass BarcodeReadFlags.None to get the default.
- multipleMaxCount
- Specifies the maximum number of barcodes to search. Pass 0 to read all barcodes in a specified search area.
- code1d
- Barcode1d class containing linear barcode options to be read.
- codePdf
- BarcodeReadPdf class containing PDF417 and MicroPDF417 barcode options to be read.
- codeColor
- BarcodeColor class containing bar and space colors to be read.
Return Value
List of BarcodeData classes in a BarcodeDataCollection class.
Visual Basic | Copy Code |
---|---|
Public Sub ReadExample() ' Load an image Dim codecs As RasterCodecs = New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "barcode1.tif")) Dim barEngine As BarcodeEngine Try ' Unlock barcode support. ' Note that this is a sample key, which will not work in your toolkit RasterSupport.Unlock(RasterSupportType.Barcodes1D, "TestKey") ' Initialize barcodes barEngine = New BarcodeEngine() Dim bar1d As Barcode1d = New Barcode1d() bar1d.Direction = BarcodeDirectionFlags.LeftToRight bar1d.ErrorCheck = True bar1d.Granularity = 9 bar1d.MaximumLength = 3 bar1d.MinimumLength = 1 bar1d.WhiteLines = 3 bar1d.OutShowText = True bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dNormal Dim barRPDF As BarcodeReadPdf = New BarcodeReadPdf() barRPDF.Direction = BarcodeDirectionFlags.LeftToRight Dim barColor As BarcodeColor = New BarcodeColor() barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black) barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White) Dim searchRect As LeadRect = LeadRect.Empty ' The Read method will search for the first 10 occurrences of the (EAN 13) barcode type ' in the bitmap region. If the bitmap does not have a region, the Read method will ' search for (EAN 13) barcodes in the whole bitmap. Dim readBarcodes As RasterCollection(Of BarcodeData) = barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch Or BarcodeReadFlags.Markers, 0, bar1d, barRPDF, barColor) Dim data1 As BarcodeData = CType(readBarcodes(0), BarcodeData) Dim count As Integer = data1.TotalCount Dim barcodeMsg As String = String.Format("Total Bar Code Symbols Found = {0}", count) Console.WriteLine(barcodeMsg) Dim i As Integer = 0 Do While i < count Dim strData As String() Dim data As BarcodeData = CType(readBarcodes(i), BarcodeData) strData = BarcodeData.ConvertToStringArray(data.Data) barcodeMsg = String.Format("No. {0}" & Constants.vbLf & "Data is {1}" & Constants.vbLf & "Type {2}" & Constants.vbLf & "Units {3}" & Constants.vbLf & "PosX {4}" & Constants.vbLf & "PosY {5}" & Constants.vbLf & "Width {6}" & Constants.vbLf & "Height {7}" & Constants.vbLf & "Group {8}" & Constants.vbLf & "Duplicate Index {9}" & Constants.vbLf, i, strData(0), data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString(), data.Group.ToString(), data.IndexDuplicate.ToString()) Console.WriteLine(barcodeMsg) i += 1 Loop Catch ex As BarcodeException Console.WriteLine(ex.Message) End Try End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class |
C# | Copy Code |
---|---|
public void ReadExample() { // Load an image RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; string fileName = Path.Combine(LEAD_VARS.ImagesDir, "barcode1.tif"); RasterImage image = codecs.Load(fileName); BarcodeEngine barEngine; try { // Unlock barcode support. // Note that this is a sample key, which will not work in your toolkit RasterSupport.Unlock(RasterSupportType.Barcodes1D, "TestKey"); // Initialize linear barcodes barEngine = new BarcodeEngine(); LeadRect searchRect = LeadRect.Empty; Barcode1d bar1d = new Barcode1d(); bar1d.Direction = BarcodeDirectionFlags.LeftToRight; bar1d.ErrorCheck = true; bar1d.Granularity = 9; bar1d.MaximumLength = 3; bar1d.MinimumLength = 1; bar1d.WhiteLines = 3; bar1d.OutShowText = true; bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dNormal; BarcodeReadPdf barRPDF = new BarcodeReadPdf(); barRPDF.Direction = BarcodeDirectionFlags.LeftToRight; BarcodeColor barColor = new BarcodeColor(); barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black); barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White); // The Read method will search for the first 10 occurrences of the (EAN 13) barcode type // in the bitmap region. If the bitmap does not have a region, the Read method will // search for (EAN 13) barcodes in the whole bitmap. RasterCollection<BarcodeData> readBarcodes = barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch | BarcodeReadFlags.Markers, 0, bar1d, barRPDF, barColor); BarcodeData data1 = (BarcodeData)readBarcodes[0]; int count = data1.TotalCount; string barcodeMsg = string.Format("Total Bar Code Symbols Found = {0}", count); Console.WriteLine(barcodeMsg); for (int i = 0; i < count; i++) { string[] strData; BarcodeData data = (BarcodeData)readBarcodes[i]; strData = BarcodeData.ConvertToStringArray(data.Data); barcodeMsg = string.Format("No. {0}\nData is {1}\nType {2}\nUnits {3}\nPosX {4}\nPosY {5}\nWidth {6}\nHeight {7}\nGroup {8}\nDuplicate Index {9}\n", i, strData[0], data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString(), data.Group.ToString(), data.IndexDuplicate.ToString()); Console.WriteLine(barcodeMsg); } } catch (BarcodeException ex) { Console.WriteLine(ex.Message); } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; } |
SilverlightCSharp | Copy Code |
---|---|
public void ReadExample(RasterImage image) { BarcodeEngine barEngine; try { // Unlock barcode support. // Note that this is a sample key, which will not work in your toolkit RasterSupport.Unlock(RasterSupportType.Barcodes1D, "TestKey"); // Initialize linear barcodes barEngine = new BarcodeEngine(); LeadRect searchRect = LeadRect.Empty; Barcode1d bar1d = new Barcode1d(); bar1d.Direction = BarcodeDirectionFlags.LeftToRight; bar1d.ErrorCheck = true; bar1d.Granularity = 9; bar1d.MaximumLength = 3; bar1d.MinimumLength = 1; bar1d.WhiteLines = 3; bar1d.OutShowText = true; bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dNormal; BarcodeReadPdf barRPDF = new BarcodeReadPdf(); barRPDF.Direction = BarcodeDirectionFlags.LeftToRight; BarcodeColor barColor = new BarcodeColor(); barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black); barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White); // The Read method will search for the first 10 occurrences of the (EAN 13) barcode type // in the bitmap region. If the bitmap does not have a region, the Read method will // search for (EAN 13) barcodes in the whole bitmap. RasterCollection<BarcodeData> readBarcodes = barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch | BarcodeReadFlags.Markers, 0, bar1d, barRPDF, barColor); BarcodeData data1 = (BarcodeData)readBarcodes[0]; int count = data1.TotalCount; string barcodeMsg = string.Format("Total Bar Code Symbols Found = {0}", count); Console.WriteLine(barcodeMsg); for (int i = 0; i < count; i++) { string[] strData; BarcodeData data = (BarcodeData)readBarcodes[i]; strData = BarcodeData.ConvertToStringArray(data.Data); barcodeMsg = string.Format("No. {0}\nData is {1}\nType {2}\nUnits {3}\nPosX {4}\nPosY {5}\nWidth {6}\nHeight {7}\nGroup {8}\nDuplicate Index {9}\n", i, strData[0], data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString(), data.Group.ToString(), data.IndexDuplicate.ToString()); Console.WriteLine(barcodeMsg); } } catch (BarcodeException ex) { Console.WriteLine(ex.Message); } } |
SilverlightVB | Copy Code |
---|---|
Public Sub ReadExample(ByVal image As RasterImage) Dim barEngine As BarcodeEngine Try ' Unlock barcode support. ' Note that this is a sample key, which will not work in your toolkit RasterSupport.Unlock(RasterSupportType.Barcodes1D, "TestKey") ' Initialize linear barcodes barEngine = New BarcodeEngine() Dim searchRect As LeadRect = LeadRect.Empty Dim bar1d As Barcode1d = New Barcode1d() bar1d.Direction = BarcodeDirectionFlags.LeftToRight bar1d.ErrorCheck = True bar1d.Granularity = 9 bar1d.MaximumLength = 3 bar1d.MinimumLength = 1 bar1d.WhiteLines = 3 bar1d.OutShowText = True bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dNormal Dim barRPDF As BarcodeReadPdf = New BarcodeReadPdf() barRPDF.Direction = BarcodeDirectionFlags.LeftToRight Dim barColor As BarcodeColor = New BarcodeColor() barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black) barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White) ' The Read method will search for the first 10 occurrences of the (EAN 13) barcode type ' in the bitmap region. If the bitmap does not have a region, the Read method will ' search for (EAN 13) barcodes in the whole bitmap. Dim readBarcodes As RasterCollection(Of BarcodeData) = barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch Or BarcodeReadFlags.Markers, 0, bar1d, barRPDF, barColor) Dim data1 As BarcodeData = CType(readBarcodes(0), BarcodeData) Dim count As Integer = data1.TotalCount Dim barcodeMsg As String = String.Format("Total Bar Code Symbols Found = {0}", count) Console.WriteLine(barcodeMsg) Dim i As Integer = 0 Do While i < count Dim strData As String() Dim data As BarcodeData = CType(readBarcodes(i), BarcodeData) strData = BarcodeData.ConvertToStringArray(data.Data) barcodeMsg = String.Format("No. {0}" & Constants.vbLf & "Data is {1}" & Constants.vbLf & "Type {2}" & Constants.vbLf & "Units {3}" & Constants.vbLf & "PosX {4}" & Constants.vbLf & "PosY {5}" & Constants.vbLf & "Width {6}" & Constants.vbLf & "Height {7}" & Constants.vbLf & "Group {8}" & Constants.vbLf & "Duplicate Index {9}" & Constants.vbLf, i, strData(0), data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString(), data.Group.ToString(), data.IndexDuplicate.ToString()) Console.WriteLine(barcodeMsg) i += 1 Loop Catch ex As BarcodeException Console.WriteLine(ex.Message) End Try End Sub |
This method supports all images currently supported by LEADTOOLS.
Use this method to recognize barcode data.
To determine whether a barcode element is duplicated or not, use BarcodeData.IsDuplicated property.
If the barcode is duplicated, you can get it by calling the BarcodeData.DuplicatedIndex method and to get the next duplicated barcode call the BarcodeData.GetNextDuplicated method.
If you know the index of a duplicated barcode, you can get the first duplicate of that barcode by calling the GetFirstDuplicatedIndex method.
When the flags parameter is set to BarcodeReadFlags.UseColors, then this method will use the codeColor parameter, otherwise the method will ignore it and use the default colors of black for bars and white for spaces.
Using colors does not apply for 1 bit per pixel images.
The BarcodeReadFlags.UseColors flag is used with all barcode types.
The BarcodeReadFlags.ReturnCheck flag is used only with reading linear barcodes.
The smallest Data Matrix symbol size is 40 pixels by 40 pixels.
It can be read using BarcodeSearchTypeFlags.DatamatrixReadSmall since this enables the reading of Data Matrix symbols that are between 20 to 40 pixels in size.
The Linear barcodes are not supported in UNICODE text.
When calling this method with the ReturnFourPoints flag set, the Location property will be updated with the coordinates of the four corners of the barcode rather than the coordinates of the bounding rectangle. These coordinates are encoded values and must be decoded before they can be used. The following example shows how to decode the four-point corner values:Point p1, p2, p3, p4; int nStartX = barData.Location.Left; int nStartY = barData.Location.Top; int nWidth = barData.Location.Right - nStartX; int nHeight = barData.Location.Bottom - nStartY; p1.X = (nStartX And 0xffff); p1.Y = (nStartX >> 16); p2.X = (nStartY And 0xffff); p2.Y = (nStartY >> 16); p3.X = (nWidth And 0xffff); p3.Y = (nWidth >> 16); p4.X = (nHeight And 0xffff); p4.Y = (nHeight >> 16);
Reading Linear Barcodes (1D):
A barcode is composed of a start mark, data, and the end mark. Reading barcodes from left to right (setting the Direction property to BarcodeDirectionFlags.LeftToRight value) or from right to left (setting the Direction property to BarcodeDirectionFlags.RightToLeft value) will produce the same result in most cases, because the barcode reader engine recognizes the start and end marks, and handles the data accordingly. For example, if BarcodeDirectionFlags.LeftToRight is used and the user reads barcodes from left to right (the barcode is not rotated), the engine will recognize the start mark first, then the data, and finally the end mark. But if the user reads barcodes from right to left (the barcode is rotated 180 degrees), the engine will first recognize the end mark, then read the (reverse-order) data, and then recognize the start mark. In this case, the engine will flip the data to normal (start/data/end) order.
Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7