LEADTOOLS Barcode (Leadtools.Barcode assembly)
LEAD Technologies, Inc

ForeColor Property (BarcodeReadOptions)

Example 







Gets or sets the barcode foreground (bars or symbol) color used when reading barcodes. .NET support Silverlight support
Syntax
[CategoryAttribute("				Colors")]
[DisplayNameAttribute("Fore color")]
[DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")]
public RasterColor ForeColor {get; set;}
'Declaration
 
<CategoryAttribute("				Colors")>
<DisplayNameAttribute("Fore color")>
<DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")>
Public Property ForeColor As RasterColor
'Usage
 
Dim instance As BarcodeReadOptions
Dim value As RasterColor
 
instance.ForeColor = value
 
value = instance.ForeColor
[CategoryAttribute("				Colors")]
[DisplayNameAttribute("Fore color")]
[DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")]
public RasterColor ForeColor {get; set;}
ObjectiveC Syntax
Java Syntax
CategoryAttribute("				Colors")
DisplayNameAttribute("Fore color")
DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")
 get_ForeColor();
set_ForeColor(value);
[CategoryAttribute("				Colors")]
[DisplayNameAttribute("Fore color")]
[DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")]
public:
property RasterColor ForeColor {
   RasterColor get();
   void set (    RasterColor value);
}

Property Value

A Leadtools.RasterColor that specifies the barcode foreground (bars or symbol) color to use when searching for barcodes. Default value is "Black" (RGB of #000000).
Remarks

If the input image is bitonal (B/W), then this value will not be used. The foreground color is always considered to be black (or the foreground color in the image palette) and the background color is always considered to be white (or the background color in the image palette).

When the input image is not bitonal, LEADTOOLS will perform intensity detect operation on the image to convert it to black and white before searching for the barcodes and uses the value of ForeColor and BackColor as the high and low threshold.

Example
Copy CodeCopy Code  
Public Sub BarcodeReadOptions_ColorsExample()
      Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode2.tif")

      ' Create a Barcode engine
      Dim engine As New BarcodeEngine()

      ' Get the Barcode reader instance
      Dim reader As BarcodeReader = engine.Reader

      Using codecs As New RasterCodecs()
         Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
            ' Invert the image
            Console.WriteLine("Inverting the image")
            Dim invert As New Leadtools.ImageProcessing.Color.InvertCommand()
            invert.Run(image)

            ' All barcodes have default options of black foreground color and white background color, so
            ' reading the barcode with default options should not return any barcodes right now

            ' Read the QR barcode from this image using default options
            Console.WriteLine("Reading using default options")
            Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, Nothing)

            ' Show its location and data if found
            ' This will print out "Not found"
            If Not IsNothing(barcode) Then
               Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value)
            Else
               Console.WriteLine("Not found")
            End If

            ' Now create QR read options to have white foreground color and black background color
            Dim qrReadOptions As New QRBarcodeReadOptions()
            qrReadOptions.ForeColor = RasterColor.FromKnownColor(RasterKnownColor.White)
            qrReadOptions.BackColor = RasterColor.FromKnownColor(RasterKnownColor.Black)

            ' And use it to try to read the QR barcode again
            Console.WriteLine("Reading using specific options that instruct the engine to look for white on black barcodes")
            barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, qrReadOptions)

            ' Show its location and data if found
            ' This will find the barcode and print its information now
            If Not IsNothing(barcode) Then
               Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value)
            Else
               Console.WriteLine("Not found")
            End If
         End Using
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void BarcodeReadOptions_ColorsExample()
   {
      string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode2.tif");

      // Create a Barcode engine
      BarcodeEngine engine = new BarcodeEngine();

      // Get the Barcode reader instance
      BarcodeReader reader = engine.Reader;

      using(RasterCodecs codecs = new RasterCodecs())
      {
         using(RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
         {
            // Invert the image
            Console.WriteLine("Inverting the image");
            Leadtools.ImageProcessing.Color.InvertCommand invert = new Leadtools.ImageProcessing.Color.InvertCommand();
            invert.Run(image);

            // All barcodes have default options of black foreground color and white background color, so
            // reading the barcode with default options should not return any barcodes right now

            // Read the QR barcode from this image using default options
            Console.WriteLine("Reading using default options");
            BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, null);

            // Show its location and data if found
            // This will print out "Not found"
            if(barcode != null)
            {
               Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value);
            }
            else
            {
               Console.WriteLine("Not found");
            }

            // Now create QR read options to have white foreground color and black background color
            QRBarcodeReadOptions qrReadOptions = new QRBarcodeReadOptions();
            qrReadOptions.ForeColor = RasterColor.FromKnownColor(RasterKnownColor.White);
            qrReadOptions.BackColor = RasterColor.FromKnownColor(RasterKnownColor.Black);

            // And use it to try to read the QR barcode again
            Console.WriteLine("Reading using specific options that instruct the engine to look for white on black barcodes");
            barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, qrReadOptions);

            // Show its location and data if found
            // This will find the barcode and print its information now
            if(barcode != null)
            {
               Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value);
            }
            else
            {
               Console.WriteLine("Not found");
            }
         }
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
public void BarcodeReadOptions_ColorsExample(RasterImage image)
{
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();
   // Get the Barcode reader instance
   BarcodeReader reader = engine.Reader;

   RasterCodecs codecs = new RasterCodecs();

   // Invert the image
   Console.WriteLine("Inverting the image");
   Leadtools.ImageProcessing.Color.InvertCommand invert = new Leadtools.ImageProcessing.Color.InvertCommand();
   invert.Run(image);

   // All barcodes have default options of black foreground color and white background color, so
   // reading the barcode with default options should not return any barcodes right now

   // Read the QR barcode from this image using default options
   Console.WriteLine("Reading using default options");
   BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, null);

   // Show its location and data if found
   // This will print out "Not found"
   if(barcode != null)
   {
      Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value);
   }
   else
   {
      Console.WriteLine("Not found");
   }

   // Now create QR read options to have white foreground color and black background color
   QRBarcodeReadOptions qrReadOptions = new QRBarcodeReadOptions();
   qrReadOptions.ForeColor = RasterColor.FromKnownColor(RasterKnownColor.White);
   qrReadOptions.BackColor = RasterColor.FromKnownColor(RasterKnownColor.Black);

   // And use it to try to read the QR barcode again
   Console.WriteLine("Reading using specific options that instruct the engine to look for white on black barcodes");
   barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, qrReadOptions);

   // Show its location and data if found
   // This will find the barcode and print its information now
   if(barcode != null)
   {
      Console.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value);
   }
   else
   {
      Console.WriteLine("Not found");
   }
}
Public Sub BarcodeReadOptions_ColorsExample(ByVal image As RasterImage)
  ' Create a Barcode engine
  Dim engine As BarcodeEngine = New BarcodeEngine()
  ' Get the Barcode reader instance
  Dim reader As BarcodeReader = engine.Reader

  Dim codecs As RasterCodecs = New RasterCodecs()

  ' Invert the image
  Console.WriteLine("Inverting the image")
    Dim invert As InvertCommand = New InvertCommand()
  invert.Run(image)

  ' All barcodes have default options of black foreground color and white background color, so
  ' reading the barcode with default options should not return any barcodes right now

  ' Read the QR barcode from this image using default options
  Console.WriteLine("Reading using default options")
  Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, Nothing)

  ' Show its location and data if found
  ' This will print out "Not found"
  If Not barcode Is Nothing Then
    Console.WriteLine("Found at {0}, data:" & Constants.vbLf & "{1}", barcode.Bounds, barcode.Value)
  Else
    Console.WriteLine("Not found")
  End If

  ' Now create QR read options to have white foreground color and black background color
  Dim qrReadOptions As QRBarcodeReadOptions = New QRBarcodeReadOptions()
  qrReadOptions.ForeColor = RasterColor.FromKnownColor(RasterKnownColor.White)
  qrReadOptions.BackColor = RasterColor.FromKnownColor(RasterKnownColor.Black)

  ' And use it to try to read the QR barcode again
  Console.WriteLine("Reading using specific options that instruct the engine to look for white on black barcodes")
  barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.QR, qrReadOptions)

  ' Show its location and data if found
  ' This will find the barcode and print its information now
  If Not barcode Is Nothing Then
    Console.WriteLine("Found at {0}, data:" & Constants.vbLf & "{1}", barcode.Bounds, barcode.Value)
  Else
    Console.WriteLine("Not found")
  End If
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

BarcodeReadOptions Class
BarcodeReadOptions Members
BackColor Property

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features