LEADTOOLS Barcode (Leadtools.Barcode assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
IsDuplicated Property
See Also 
Leadtools.Barcode Namespace > BarcodeData Class : IsDuplicated Property



(Read-only) Gets a value that indicates whether the specified barcode is duplicated.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property IsDuplicated As Boolean
Visual Basic (Usage)Copy Code
Dim instance As BarcodeData
Dim value As Boolean
 
value = instance.IsDuplicated
C# 
public bool IsDuplicated {get;}
C++/CLI 
public:
property bool IsDuplicated {
   bool get();
}

Property Value

true, the barcode is duplicated; false, the barcode is not duplicated.

Example

Visual BasicCopy Code
Public Sub IsDuplicatedPropertyExample()
      ' 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

      Dim dupIndex, dupCount As Integer
      Dim msg As String

      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 barColor As BarcodeColor = New BarcodeColor()
         Dim searchRect As LeadRect = LeadRect.Empty
         barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black)
         barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White)

         Dim readBarcodes As RasterCollection(Of BarcodeData) = barEngine.Read(image, _
                                             searchRect, _
                                             BarcodeSearchTypeFlags.Barcode1dEan13, _
                                             BarcodeUnit.ScanlinesPerPixels, _
                                             BarcodeReadFlags.BlockSearch Or BarcodeReadFlags.Markers, _
                                             0, _
                                             Nothing, Nothing, barColor)

         Dim data As BarcodeData = CType(readBarcodes(0), BarcodeData)
         If data.IsDuplicated Then
            dupIndex = data.GetFirstDuplicatedIndex(data.DuplicatedIndex)
            dupCount = data.DuplicateCount

            msg = String.Format("This Bar Code was found in {0} different locations.", dupCount)
            Console.WriteLine(msg)

            ' Display the first duplicate barcode information.

            Dim strData As String()

            data = CType(readBarcodes(dupIndex), BarcodeData)
            strData = BarcodeData.ConvertToStringArray(data.Data)

            msg = 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}", dupIndex, strData(0), data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString())

            Console.WriteLine(msg)

            dupIndex = data.GetNextDuplicated(dupIndex)
            If dupIndex <> -1 Then
               ' Display the next duplicate barcode information.
               data = CType(readBarcodes(dupIndex), BarcodeData)
               strData = BarcodeData.ConvertToStringArray(data.Data)

               msg = 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}", dupIndex, strData(0), data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString())

               Console.WriteLine(msg)
            End If
         Else
            Console.WriteLine("This Barcode is not duplicated ...")
         End If
      Catch ex As Exception
         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 IsDuplicatedPropertyExample()
   {
      // 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;
      int dupIndex, dupCount;
      string msg;

      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();

         BarcodeColor barColor = new BarcodeColor();

         LeadRect searchRect = LeadRect.Empty;
         barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black);
         barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White);

         RasterCollection<BarcodeData> readBarcodes = barEngine.Read(image,
                                       searchRect,
                                       BarcodeSearchTypeFlags.Barcode1dEan13,
                                       BarcodeUnit.ScanlinesPerPixels,
                                       BarcodeReadFlags.BlockSearch | BarcodeReadFlags.Markers,
                                       0, null, null, barColor);

         BarcodeData data = (BarcodeData)readBarcodes[0];
         if (data.IsDuplicated)
         {
            dupIndex = data.GetFirstDuplicatedIndex(data.DuplicatedIndex);
            dupCount = data.DuplicateCount;

            msg = string.Format("This Bar Code was found in {0} different locations.", dupCount);
            Console.WriteLine(msg);

            // Display the first duplicate barcode information.

            string[] strData;

            data = (BarcodeData)readBarcodes[dupIndex];
            strData = BarcodeData.ConvertToStringArray(data.Data);

            msg = string.Format("No. {0}\nData is {1}\nType {2}\nUnits {3}\nPosX {4}\nPosY {5}\nWidth {6}\nHeight {7}",
               dupIndex,
               strData[0],
               data.SearchType.ToString(),
               data.Unit.ToString(),
               data.Location.Left.ToString(),
               data.Location.Top.ToString(),
               data.Location.Width.ToString(),
               data.Location.Height.ToString());

            Console.WriteLine(msg);

            dupIndex = data.GetNextDuplicated(dupIndex);
            if (dupIndex != -1)
            {
               // Display the next duplicate barcode information.
               data = (BarcodeData)readBarcodes[dupIndex];
               strData = BarcodeData.ConvertToStringArray(data.Data);

               msg = string.Format("No. {0}\nData is {1}\nType {2}\nUnits {3}\nPosX {4}\nPosY {5}\nWidth {6}\nHeight {7}",
                  dupIndex,
                  strData[0],
                  data.SearchType.ToString(),
                  data.Unit.ToString(),
                  data.Location.Left.ToString(),
                  data.Location.Top.ToString(),
                  data.Location.Width.ToString(),
                  data.Location.Height.ToString());

               Console.WriteLine(msg);
            }
         }
         else
            Console.WriteLine("This Barcode is not duplicated ...");
      }
      catch (Exception ex)
      {
         Console.WriteLine(ex.Message);
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
public void IsDuplicatedPropertyExample(RasterImage image)
{
   BarcodeEngine barEngine;
   int dupIndex, dupCount;
   string msg;
   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();

      BarcodeColor barColor = new BarcodeColor();

      LeadRect searchRect = LeadRect.Empty;
      barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black);
      barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White);

      RasterCollection<BarcodeData> readBarcodes = barEngine.Read(image,
                                    searchRect,
                                    BarcodeSearchTypeFlags.Barcode1dEan13,
                                    BarcodeUnit.ScanlinesPerPixels,
                                    BarcodeReadFlags.BlockSearch | BarcodeReadFlags.Markers,
                                    0, null, null, barColor);

      BarcodeData data = (BarcodeData)readBarcodes[0];
      if (data.IsDuplicated)
      {
         dupIndex = data.GetFirstDuplicatedIndex(data.DuplicatedIndex);
         dupCount = data.DuplicateCount;

         msg = string.Format("This Bar Code was found in {0} different locations.", dupCount);
         Console.WriteLine(msg);

         // Display the first duplicate barcode information.

         string[] strData;

         data = (BarcodeData)readBarcodes[dupIndex];
         strData = BarcodeData.ConvertToStringArray(data.Data);

         msg = string.Format("No. {0}\nData is {1}\nType {2}\nUnits {3}\nPosX {4}\nPosY {5}\nWidth {6}\nHeight {7}",
            dupIndex,
            strData[0],
            data.SearchType.ToString(),
            data.Unit.ToString(),
            data.Location.Left.ToString(),
            data.Location.Top.ToString(),
            data.Location.Width.ToString(),
            data.Location.Height.ToString());

         Console.WriteLine(msg);

         dupIndex = data.GetNextDuplicated(dupIndex);
         if (dupIndex != -1)
         {
            // Display the next duplicate barcode information.
            data = (BarcodeData)readBarcodes[dupIndex];
            strData = BarcodeData.ConvertToStringArray(data.Data);

            msg = string.Format("No. {0}\nData is {1}\nType {2}\nUnits {3}\nPosX {4}\nPosY {5}\nWidth {6}\nHeight {7}",
               dupIndex,
               strData[0],
               data.SearchType.ToString(),
               data.Unit.ToString(),
               data.Location.Left.ToString(),
               data.Location.Top.ToString(),
               data.Location.Width.ToString(),
               data.Location.Height.ToString());

            Console.WriteLine(msg);
         }
      }
      else
         Console.WriteLine("This Barcode is not duplicated ...");
   }
   catch (Exception ex)
   {
      Console.WriteLine(ex.Message);
   }
}
SilverlightVBCopy Code
Public Sub IsDuplicatedPropertyExample(ByVal image As RasterImage)
  Dim barEngine As BarcodeEngine
  Dim dupIndex, dupCount As Integer
  Dim msg As String
  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 barColor As BarcodeColor = New BarcodeColor()

    Dim searchRect As LeadRect = LeadRect.Empty
    barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black)
    barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White)

    Dim readBarcodes As RasterCollection(Of BarcodeData) = barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch Or BarcodeReadFlags.Markers, 0, Nothing, Nothing, barColor)

    Dim data As BarcodeData = CType(readBarcodes(0), BarcodeData)
    If data.IsDuplicated Then
       dupIndex = data.GetFirstDuplicatedIndex(data.DuplicatedIndex)
       dupCount = data.DuplicateCount

       msg = String.Format("This Bar Code was found in {0} different locations.", dupCount)
       Console.WriteLine(msg)

       ' Display the first duplicate barcode information.

       Dim strData As String()

       data = CType(readBarcodes(dupIndex), BarcodeData)
       strData = BarcodeData.ConvertToStringArray(data.Data)

       msg = 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}", dupIndex, strData(0), data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString())

       Console.WriteLine(msg)

       dupIndex = data.GetNextDuplicated(dupIndex)
       If dupIndex <> -1 Then
         ' Display the next duplicate barcode information.
         data = CType(readBarcodes(dupIndex), BarcodeData)
         strData = BarcodeData.ConvertToStringArray(data.Data)

         msg = 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}", dupIndex, strData(0), data.SearchType.ToString(), data.Unit.ToString(), data.Location.Left.ToString(), data.Location.Top.ToString(), data.Location.Width.ToString(), data.Location.Height.ToString())

         Console.WriteLine(msg)
       End If
    Else
       Console.WriteLine("This Barcode is not duplicated ...")
    End If
  Catch ex As Exception
    Console.WriteLine(ex.Message)
  End Try
End Sub

Remarks

This property determines whether a barcode is duplicated in another location in the image.

LEADTOOLS provides a number of functions to let you work with duplicated barcodes. They let you:

  • Find the number of duplicates of a specific barcode
  • Determine whether a specific barcode is duplicated
  • Get the index of the first duplicated barcode
  • Get the index of a subsequent barcode

To determine whether a barcode is duplicated, use the IsDuplicated property. If a barcode is duplicated, the DuplicatedIndex property will return the index of the first barcode in the array after the specified barcode, which is a duplicate of the specified barcode. The DuplicateCount property will get the total number of barcodes duplicated for the current barcode.

If you know the index of a barcode within an array, use the IndexDuplicate property to get the next instance of a duplicated barcode. Call the GetFirstDuplicatedIndex method to find the index of the first barcode in the array that is a duplicate of the barcode at the specified index. Call the GetNextDuplicated method to find the index of the next barcode in the array that is a duplicate of the barcode at the specified index.

To find out how many sets of barcodes are duplicated (for example, in an array of ten barcodes, the first, third, and fifth might be duplicates of each other, while the 4th, 8th and 9th are duplicates of a different barcode), use the following code:

VB

 Private Function GetSetsCount(ByRef barcodeData As RasterCollection(Of BarcodeData)) As 
            Integer
Dim i As Integer
Dim j As Integer
Dim count As Integer
Dim visited() As Boolean
ReDim visited(barcodeData.Count)

 count = 0
For i = 0 To barcodeData.Count - 1
If visited(i) Then
Continue For
End If
visited(i) = True
count += 1
j = i
While barcodeData(j).IndexDuplicate &lt;&gt; -1 And barcodeData(j).IndexDuplicate &lt;&gt; 255
j = barcodeData(j).IndexDuplicate
visited(j) = True
End While
Next
Return count
End Function

C#

public int GetSetsCount(RasterCollection&lt;BarcodeData&gt; barcodeData)
{
int i, j, count;
bool [] visited = new bool [barcodeData.Count];
count = 0;
for (i = 0; i &lt; barcodeData.Count; i++)
{
if (visited[i])
continue;
visited[i] = true;
count++;
j = i;
while (barcodeData[j].IndexDuplicate != -1 &amp;&amp;
barcodeData[j].IndexDuplicate != 255)
{
j = barcodeData[j].IndexDuplicate;
visited[j] = true;
}
}
return count;
}

After this code is executed, count will contain the number of different sets of barcodes.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features