Get Barcode128 Dimension from Vintasoft

Questions, comments and suggestions concerning VintaSoft Barcode .NET SDK.

Moderator: Alex

Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Get Barcode128 Dimension from Vintasoft

Post by Alex »

Hello,
IAmByB wrote: I have one more question about Vintasoft barcodes writer :

If I create a barcode 128 with :
SetMinWidth(0.375,MeasurementUnit.Millimeters);
the value of MinWidth property is 2 px

If I create a barcode 128 with :
SetMinWidth(0.7,MeasurementUnit.Millimeters);
the value of MinWidth property is the same (2 px)

I thought that the MinWidth value was going to change when I change the value used in SetMinWidth().

Can you explain me why is the MinWidth value the same in both cases, and how can I make vary ?
The Vintasoft.Barcode.WriterSettings.SetMinWidth method allows to specify the desired width of bar. The method allows to specify the desired width in any unit of measure but the resulting value is stored as integer value and represents the bar width in pixels.

You are using the following code:

Code: Select all

barcodeWriterSettings.Resolution = 72;
barcodeWriterSettings.SetMinWidth(0.375, MeasurementUnit.Millimeters);
//barcodeWriterSettings.SetMinWidth(0.7, MeasurementUnit.Millimeters);
Here is how algorithm works:
  • Algorithm calculates the bar width in pixels as a float value:
    • (0.375 * 72) / 25.4 = 1.063 pixels
    • (0.7 * 72) / 25.4 = 1.984 pixels
  • Algorithms rounds the bar width to the nearest integer value:
    • Round(1.063) = 2 pixels
    • Round(1.984) = 2 pixels

The bar width in pixels is stored as the integer value because SDK generates ideal barcodes and SDK guarantees that generated barcode can be recognized. Also the bar width cannot be specified by a float value because the float value cannot be positioned correctly on the pixel grid of raster image and as a result the barcode image can lose the correct information about the bar widths.

You can scale the generated barcode image but in this case we cannot guarantee that barcode will be recognized because you can lose the correct information about the bar widths.

As I know you want to add the barcode to a PDF document. PDF document is a vector document and I suggest you to generate barcode in vector form and add the vector graphics to a PDF document. Later you will be able to render PDF document with any resolution (72, 100, 150, 200, 300, etc) and your barcode will be rendered correctly and has good quality.

Best regards, Alexander
Post Reply