LEADTOOLSバーコード(Leadtools.Barcodeアセンブリ)

フレームを表示

ForeColorプロパティ(BarcodeReadOptions)








バーコードを読むとき、カラーが使ったバーコード前景(バーまたはシンボル)を取得または設定します。
構文
[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;}
@property (nonatomic, copy) LTRasterColor *foreColor
public RasterColor getForeColor()
public void setForeColor(RasterColor value)
            
CategoryAttribute("				Colors")
DisplayNameAttribute("Fore color")
DescriptionAttribute("Foreground (bar) color to use when searching for barcodes")
 <br/>get_ForeColor();<br/>set_ForeColor(value);<br/>Object.defineProperty('ForeColor'); 
[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);
}

属性値

バーコードを検索するとき、使うバーコードフォアグラウンドの(バーまたはシンボル)カラーを指定するRasterColor。デフォルト値は、「黒いです」(#000000のRGB)。
解説

入力イメージが2値画像(モノクロ)であるならば、この値が使われません。前景色は常に黒い(またはimageパレットの前景色)と考えられます、そして、背景色は常に白い(またはimageパレットの背景色)と考えられます。

入力イメージが2値画像でないとき、LEADTOOLSはバーコードを検索する前に白黒にそれを変換するためにimageの上で強度検出操作を実行して、上下のしきい値としてForeColorBackColorの値を使います。

サンプル

このサンプルは、特定の色でimageからバーコードを読みます。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing

      
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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

      
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";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;
using Leadtools.Examples;

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");
   }
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color

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
必要条件

ターゲットプラットホーム

参照

参照

BarcodeReadOptionsクラス
BarcodeReadOptionsメンバ
BackColorプロパティ

Leadtools.Barcodeは、バーコードモジュールのライセンスと、解除キーが必要です。詳細は、以下を参照してください。LEADTOOLSツールキット機能