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 > IBarcodeWriteOptions Interface : ForeColor Property |
[CategoryAttribute(" Colors")] [DisplayNameAttribute("Fore color")] [DescriptionAttribute("Foreground (bar) color to use when writing the barcode")] RasterColor ForeColor {get; set;}
'Declaration
<CategoryAttribute(" Colors")> <DisplayNameAttribute("Fore color")> <DescriptionAttribute("Foreground (bar) color to use when writing the barcode")> Property ForeColor As RasterColor
'Usage
Dim instance As IBarcodeWriteOptions Dim value As RasterColor instance.ForeColor = value value = instance.ForeColor
[CategoryAttribute(" Colors")] [DisplayNameAttribute("Fore color")] [DescriptionAttribute("Foreground (bar) color to use when writing the barcode")] RasterColor ForeColor {get; set;}
CategoryAttribute(" Colors") DisplayNameAttribute("Fore color") DescriptionAttribute("Foreground (bar) color to use when writing the barcode") <br/>get_ForeColor();<br/>set_ForeColor(value);<br/>Object.defineProperty('ForeColor');
[CategoryAttribute(" Colors")] [DisplayNameAttribute("Fore color")] [DescriptionAttribute("Foreground (bar) color to use when writing the barcode")] property RasterColor ForeColor { RasterColor get(); void set ( RasterColor value); }
LEADTOOLS will use ForeColor and BackColor when drawing the new barcode to the image and no special processing is performed. Note that you can specify a transparent color for BackColor to "overlay" the barcode on top of the background of the image. This however, is not recommended.
This example writes a UPC-A barcode to an image with specific colors.
using Leadtools; using Leadtools.Codecs; using Leadtools.Barcode; using Leadtools.ImageProcessing; public async Task BarcodeWriteOptions_ColorsExample() { string imageFileName = @"MyBarcode.png"; BarcodeEngine engine = new BarcodeEngine(); BarcodeWriter writer = engine.Writer; // We will create a Red over Yellow backround RasterColor foreColor = RasterColorHelper.FromKnownColor(RasterKnownColor.Red); RasterColor backColor = RasterColorHelper.FromKnownColor(RasterKnownColor.Yellow); // Create a UPC-A barcode BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA); barcode.Bounds = LeadRectHelper.Create(0, 0, 400, 200); // Create a 24 BPP image the same size as the barcode // The image will have red over yellow colors int resolution = 300; LeadRect pixels = barcode.Bounds; using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 24, resolution, backColor)) { // Change the barcode colors to be Red over Yellow OneDBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; options.ForeColor = foreColor; options.BackColor = backColor; // Write the barcode writer.WriteBarcode(image, barcode, options); // Save as PNG using(RasterCodecs codecs = new RasterCodecs()) { StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(imageFileName); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Png, 24); } } }