←Select platform

ForeColor Property

Summary
Gets or sets the barcode foreground (bars or symbol) color used when writing barcodes.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterColor ForeColor { get; set; } 
@property (nonatomic, copy) LTRasterColor *foreColor; 
public RasterColor getForeColor() 
public void setForeColor(RasterColor value) 
public: 
property RasterColor ForeColor { 
   RasterColor get(); 
   void set (    RasterColor ); 
} 
ForeColor # get and set (BarcodeWriteOptions) 

Property Value

A RasterColor that specifies the barcode foreground (bars or symbol) color when writing barcodes. Default value is "Black" (RGB of #000000). The default value is #FF000000.

Remarks

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.

Example

This example writes a UPC-A barcode to an image with specific colors.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
public void BarcodeWriteOptions_ColorsExample() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.png"); 
 
   BarcodeEngine engine = new BarcodeEngine(); 
   BarcodeWriter writer = engine.Writer; 
 
   // We will create a Red over Yellow backround 
   RasterColor foreColor = RasterColor.FromKnownColor(RasterKnownColor.Red); 
   RasterColor backColor = RasterColor.FromKnownColor(RasterKnownColor.Yellow); 
 
   // Create a UPC-A barcode 
   BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA); 
   barcode.Bounds = new LeadRect(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()) 
      { 
         codecs.Save(image, imageFileName, RasterImageFormat.Png, 24); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.Console; 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Path; 
import java.time.LocalDateTime; 
 
import org.apache.lucene.store.Directory; 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
 
 
public void BarcodeWriteOptions_ColorsExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String imageFileName = combine(LEAD_VARS_ImagesDir, "MyBarcode.png"); 
 
   BarcodeEngine engine = new BarcodeEngine(); 
   BarcodeWriter writer = engine.getWriter(); 
 
   // We will create a Red over Yellow backround 
   RasterColor foreColor = RasterColor.fromKnownColor(RasterKnownColor.RED); 
   RasterColor backColor = RasterColor.fromKnownColor(RasterKnownColor.YELLOW); 
 
   // Create a UPC-A barcode 
   BarcodeData barcode = BarcodeData.createDefaultBarcodeData(BarcodeSymbology.UPC_A); 
   barcode.setBounds(new LeadRect(0, 0, 400, 200)); 
   assertTrue(barcode.getBounds() != null); 
 
   // 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.getBounds(); 
   RasterImage image = RasterImage.create(pixels.getWidth(), pixels.getHeight(), 24, resolution, backColor); 
   assertTrue(image != null); 
 
   // Change the barcode colors to be Red over Yellow 
   OneDBarcodeWriteOptions options = (OneDBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.UPC_A); 
   options.setForeColor(foreColor); 
   options.setBackColor(backColor); 
 
   // Write the barcode 
   writer.writeBarcode(image, barcode, options); 
 
   // Save as PNG 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.save(image, imageFileName, RasterImageFormat.PNG, 24); 
   assertTrue((new File(imageFileName)).exists()); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.