Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.22
|
Leadtools.Barcode Namespace > IBarcodeReadOptions Interface : ForeColor Property |
[CategoryAttribute(" Colors")] [DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")] [DisplayNameAttribute("Fore color")] RasterColor ForeColor {get; set;}
'Declaration
<CategoryAttribute(" Colors")> <DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")> <DisplayNameAttribute("Fore color")> Property ForeColor As RasterColor
'Usage
Dim instance As IBarcodeReadOptions Dim value As RasterColor instance.ForeColor = value value = instance.ForeColor
[CategoryAttribute(" Colors")] [DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")] [DisplayNameAttribute("Fore color")] RasterColor ForeColor {get; set;}
CategoryAttribute(" Colors") DescriptionAttribute("Foreground (bar) color to use when searching for barcodes") DisplayNameAttribute("Fore color") <br/>get_ForeColor();<br/>set_ForeColor(value);<br/>Object.defineProperty('ForeColor');
[CategoryAttribute(" Colors")] [DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")] [DisplayNameAttribute("Fore color")] property RasterColor ForeColor { RasterColor get(); void set ( RasterColor value); }
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.
This example reads a barcode from an image with specific colors.
using Leadtools; using Leadtools.Codecs; using Leadtools.Barcode; using Leadtools.ImageProcessing; public async Task BarcodeReadOptions_ColorsExample() { string imageFileName = @"Assets\Barcode2.tif"; // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode reader instance BarcodeReader reader = engine.Reader; using(RasterCodecs codecs = new RasterCodecs()) { StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName); using(RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile))) { // Invert the image Debug.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 Debug.WriteLine("Reading using default options"); BarcodeData barcode = reader.ReadBarcode(image, LeadRectHelper.Empty, BarcodeSymbology.QR, null); // Show its location and data if found // This will print out "Not found" if(barcode != null) { Debug.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value); } else { Debug.WriteLine("Not found"); } // Now create QR read options to have white foreground color and black background color QRBarcodeReadOptions qrReadOptions = new QRBarcodeReadOptions(); qrReadOptions.ForeColor = RasterColorHelper.FromKnownColor(RasterKnownColor.White); qrReadOptions.BackColor = RasterColorHelper.FromKnownColor(RasterKnownColor.Black); // And use it to try to read the QR barcode again Debug.WriteLine("Reading using specific options that instruct the engine to look for white on black barcodes"); barcode = reader.ReadBarcode(image, LeadRectHelper.Empty, BarcodeSymbology.QR, qrReadOptions); // Show its location and data if found // This will find the barcode and print its information now if(barcode != null) { Debug.WriteLine("Found at {0}, data:\n{1}", barcode.Bounds, barcode.Value); } else { Debug.WriteLine("Not found"); } } } }