Barcode write: the result change by upgrading from version 7.7 to 23.6

Hi, we were using a old version of Aspose.Barcode (V 7.7).
A few months ago we upgrated to 23.6 and we converted the code.
Today, we noticed that the result is now different.

This is the old code (V 7.7):

Using destinationImageStream As IO.Stream = IO.File.OpenWrite("barcode_old.png")

	Dim writer As New Aspose.BarCode.BarCodeBuilder
	writer.CodeText = "1234567"
	writer.SymbologyType = Aspose.BarCode.Symbology.Code128
	writer.CodeLocation = Aspose.BarCode.CodeLocation.None
	writer.CodeTextAlignment = StringAlignment.Center
	writer.ImageHeight = 150
	writer.ImageWidth = 450
	writer.AutoSize = True
	writer.GraphicsUnit = GraphicsUnit.Millimeter

End Using
Process.Start("barcode_old.png")

And this is the ported code (V 23.6)

Using destinationImageStream As IO.Stream = IO.File.OpenWrite("barcode_new.png")

	Dim generator As New Generation.BarcodeGenerator(Generation.EncodeTypes.Code128, "1234567")

	generator.Parameters.Barcode.CodeTextParameters.Location = Generation.CodeLocation.None
	generator.Parameters.Barcode.CodeTextParameters.Alignment = Generation.TextAlignment.Center

	generator.Parameters.ImageHeight.Millimeters = 150
	generator.Parameters.ImageWidth.Millimeters = 450
	generator.Parameters.AutoSizeMode = Generation.AutoSizeMode.None

	generator.Save(destinationImageStream, Generation.BarCodeImageFormat.Png)

End Using
Process.Start("barcode_new.png")

Is there any issue on porting the code to the latest version on Aspose.Barcode or this one simply generates a different barcode image?
Can we generate with V 26.6 an identical image of the barcode, like in V 7.7?

Thank you for any suggestion.

barcode_new.png (126 Bytes)

barcode_old.png (115 Bytes)

@gmarre,

Thanks for the details.

After an initial test, I found difference when using your sample code segment to generate the barcode image. I found the result is changed a bit in the newer versions. We will evaluate your code segment if we can do some tweaks to mimic the older barcode image (result) you shared.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): BARCODENET-38904

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

This article helps you to understand new changes to Barcode Appearance

About your code:

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567");

generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
//you do not need this row because CodeLocation.None hides CodeText
//generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center;

//Millimeters depend on Resolution which can be set in generator.Parameters.Resolution
//In this way standard resolution for screen 96 dpi (pixels per inch), for printing 300 dpi. 1 inch = 25.4 Millimeters
generator.Parameters.ImageHeight.Pixels = 150;
generator.Parameters.ImageWidth.Pixels = 450;

//AutoSizeMode.None ignores ImageHeight and ImageWidth in parameters
//AutoSizeMode.Nearest fits to closest size without corruption of barcode propotions
//AutoSizeMode.Interpolation directly fit barcode to size but corrupts barcode propotions and can make barcode unrecognizable
generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Nearest;

generator.Save(@"d:\save\rec\code128.png", BarCodeImageFormat.Png);

The code which generated similar barcode image:

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567");
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;

//AutoSizeMode.None is set by default
generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.None;

generator.Parameters.Barcode.XDimension.Pixels = 2;
generator.Parameters.Barcode.BarHeight.Pixels = 57;

//padding section
generator.Parameters.Barcode.Padding.Left.Pixels = 16;
generator.Parameters.Barcode.Padding.Top.Pixels = 4;
generator.Parameters.Barcode.Padding.Right.Pixels = 14;
generator.Parameters.Barcode.Padding.Bottom.Pixels = 4;

generator.Save(@"d:\save\rec\code128.png", BarCodeImageFormat.Png);

Hi, our custumers use this functionality to print the barcode to a label printer.
So, the size of the barcode depends on the size of the printer label.
We do not know before and the code I proposed is only an example of possible size.
So, I think is hard for us to calculate calculate paddings or barheight to obtain a similar barcode…

So, can you consider a bug if a new version of your library generate a different barcode with same parameters? And, if yes can you consider to fix it?

Thank you

@gmarre,

We have logged your concerns against the existing ticket “BARCODENET-38904” into our database. We will evaluate and get back to you with updates.

The bug exists in the old library version with BarCodeBuilder, but it has a lot of other issues. Because of this we have developed BarcodeGenerator where most of issues was fixed (some of them appear periodically and we fix).

About your old code. As I understand you want to generate Code128 barcode with default resolution 96 dpi and autosized to 450 mm width and 150 mm height. The real size in pixels should be:
(450 / 25.4 (millimeters in inches)) * 96 (pixels in inch) = 1701 pixels
(150 / 25.4 (millimeters in inches)) * 96 (pixels in inch) = 567 pixels

But size of generated by BarCodeBuilder image is 210x65. And this is bug (no, we will not fix bug in BarCodeBuilder).

You can read information about resolution and different measurement units in this article.

About BarcodeGenerator, it generates directly what you want. I recommend to use 300 dpi as printing dpi, so the code is built with 300 dpi resolution.

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567");
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;

//printing resolution 300dpi
generator.Parameters.Resolution = 300;

//450 * 150 mm image
generator.Parameters.ImageHeight.Millimeters = 150;
generator.Parameters.ImageWidth.Millimeters = 450;

//autosize without interpolation
generator.Parameters.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Nearest;

//zero padding around
generator.Parameters.Barcode.Padding.Left.Millimeters = 0;
generator.Parameters.Barcode.Padding.Top.Millimeters = 0;
generator.Parameters.Barcode.Padding.Right.Millimeters = 0;
generator.Parameters.Barcode.Padding.Bottom.Millimeters = 0;

generator.Save(@"d:\save\rec\code128_autosized.png", BarCodeImageFormat.Png);

And generated image:
code128_autosized.png (210.2 KB)

So 450 mm x 150 mm with 300 dpi:
(450 / 25.4 (millimeters in inches)) * 300 (pixels in inch) = 5315 pixels
(150 / 25.4 (millimeters in inches)) * 300 (pixels in inch) = 1772 pixels

The image size is 5314x1771, fits directly, may be with rounding 1 pixel error.

Hi, thank you for your explanations.
If I have right understand you, the bug was in old version, so you cannot fix it, obviously!
Anyway, now, thanks to your suggested code, I tried successfully to obtain a similar barcode with new library version and that’s ok for me, so thank you.

@gmarre,

Your understanding is correct; it was a bug in the older versions. It’s good to know that the suggested code segment with details helped you figure out your issue. Please feel free to write back to us if you have further queries or comments.