VintaSoft Barcode .NET SDK Discussions
Questions, comments and suggestions concerning VintaSoft Barcode .NET SDK.
Board index < VintaSoft Barcode < VintaSoft Barcode .NET SDK Discussions
(lbInfos is a ListBox on my form).
public void ReadBarcodesFromImage(Image barcodeImage)
{
lbInfos.Items.Clear();
// create barcode reader
BarcodeReader reader = new BarcodeReader();
// specify that reader must search for Code39, Code39Extended,
// Code128, SSCC18 and DataMatrix barcodes
reader.Settings.ScanBarcodeTypes =
BarcodeType.Code39 |
BarcodeType.Code128 |
BarcodeType.DataMatrix;
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.Code39Extended);
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.SSCC18);
// specify that reader must search for horizontal and vertical barcodes only
reader.Settings.ScanDirection = ScanDirection.Horizontal | ScanDirection.Vertical;
// use Automatic Recognition
reader.Settings.AutomaticRecognition = true;
// read barcodes from image
IBarcodeInfo[] infos = reader.ReadBarcodes(barcodeImage);
// if barcodes are not detected
if (infos.Length == 0)
{
Console.WriteLine("No barcodes found.");
}
// if barcodes are detected
else
{
// get information about extracted barcodes
Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
Console.WriteLine();
for (int i = 0; i < infos.Length; i++)
{
IBarcodeInfo info = infos[i];
lbInfos.Items.Add(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
lbInfos.Items.Add(string.Format("Value: {0}", info.Value));
lbInfos.Items.Add(string.Format("Region: {0}", info.Region));
}
}
}
Yes, I want to get the bar width value of the recognized barcode (I understand it is the MinWidth value I can set in the Vintasoft barcode writer).The BarcodeInfo1D.NarrowBarCount property returns the bar count in the recognized barcode:
writer.Settings.SetMinWidth(0.375, UnitOfMeasure.Millimeters);but when I read the barcode I created, the NarrowBar Size value read by Vintasoft is 4.6.
using System;
using System.Drawing;
using Vintasoft.Barcode;
using Vintasoft.Barcode.BarcodeInfo;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
BarcodeWriter barcodeWriter = new BarcodeWriter();
barcodeWriter.Settings.Barcode = BarcodeType.Code128;
barcodeWriter.Settings.Value = "1234567890";
barcodeWriter.Settings.Resolution = 72;
barcodeWriter.Settings.SetMinWidth(0.375, UnitOfMeasure.Millimeters);
if (barcodeWriter.Settings.MinWidth != 2)
throw new ApplicationException();
using (Bitmap bitmap = barcodeWriter.GetBarcodeAsBitmap())
{
using (BarcodeReader barcodeReader = new BarcodeReader())
{
barcodeReader.Settings.ScanBarcodeTypes = BarcodeType.Code128;
IBarcodeInfo[] infos = barcodeReader.ReadBarcodes(bitmap);
if (infos.Length != 1)
throw new ApplicationException();
BarcodeInfo1D info1D = infos[0] as BarcodeInfo1D;
if (info1D.NarrowBarSize != 2)
throw new ApplicationException();
}
}
}
}
}
Please try to use this code and let me know if you will have any question or problem.Can you please tell me what is the measurement unit of the MinWidth value (not the 0.375 value but the 2 value) ?The WriterSettings.MinWidth property value is specified in pixels: