Barcode Resolution - Size

Hi,


I am using the code below to generate a Code128 barcode. When using the default resolution (96 dpi) it seems the CodeTextAlignment ‘Center’ doesn’t work and the CodeText is not centered.

When changing the resolution to 97 dpi, the text actually gets centered correctly but the aspect ratio of the barcode image changes and it becomes much wider.

When changing the resolution to 300 dpi for better quality of the code text the barcode image becomes even wider.

Is this normal behavior?

As a secondary question: Is there a way to adjust/remove the white space below the code text? I can change the margins of barcode easely but not below the code text.

//Instantiate linear barcode object
using (BarCodeBuilder builder = new BarCodeBuilder())
{
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;

//Set the Code text for the barcode
builder.CodeText = “6040223579”;

//default resolution
builder.Resolution = new Aspose.BarCode.Resolution(96, 96, ResolutionMode.Graphics);

//Set the symbology type to Code128
builder.SymbologyType = Symbology.Code128;

//Set the rotation angle of the barcode
builder.RotationAngleF = 0;

builder.BarHeight = 4;
builder.yDimension = 4;

//doesn’t work at 96 dpi
builder.CodeTextAlignment = StringAlignment.Center;

builder.CodeLocation = CodeLocation.Below;
builder.CaptionAbove = null;

//Save image to view result
builder.BarCodeImage.Save(@“c:\testtiffbc.tif”, System.Drawing.Imaging.ImageFormat.Tiff);
}

Best Regards
Hi Johan,

Thank you for your inquiry and sharing sample code.

Sorry for the late reply. This is to update you that we have evaluated the code shared by you. The code text in the output barcode is at center. When you use the option code text alignment to center it will align the text to center. You can observe it by opening the output barcode image into MS Paint. Enable “Gridlines” under “View” menu. Sample output barcode images are attached for your reference. The only difference is the horizontal and vertical resolution due to which you will see the resultant image big or small.

Furthermore you may use the following code sample to remove unwanted white space at the bottom of barcode image.

Hope the above information helps. Feel free to contact us in case of any query or comments.

CODE:

using (BarCodeBuilder builder = new BarCodeBuilder())
{
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;

//Set the Code text for the barcode
builder.CodeText = "6040223579";
//default resolution
builder.Resolution = new Aspose.BarCode.Resolution(96, 96, ResolutionMode.Graphics);
//Set the symbology type to Code128
builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.Code128;
//Set the rotation angle of the barcode
builder.RotationAngleF = 0;
builder.BarHeight = 4;
builder.yDimension = 4;
builder.CodeTextAlignment = System.Drawing.StringAlignment.Center;
builder.CodeLocation = CodeLocation.Below;
builder.CaptionAbove = null;
builder.SupplementSpace = 0;
builder.CodeTextSpace = 0;

//Save image to view result
builder.BarCodeImage.Save(@"test_barcode_1.tif", System.Drawing.Imaging.ImageFormat.Tiff);
}

Hi Ikram,


If I check the pixel the pixel size of your 3 samples I get the following:

96dpi: 210x43
97dpi: 211x44
300dpi: 724x136

If I calculate the ratio Width / Height I get:

96dpi: 210/43 = 4.88
300dpi: 724/136 = 5.32

meaning the 300 dpi image is quite a bit wider compared to its height, then the 96dpi image.

Secondly there seems to be a difference between WPF and Winforms.

I created a blank WPF and Windows Forms application in Visual Studio 2015. On each I added the latest Aspose.Barcode from NuGet and I put your exact sample code below the InitializeComponent() function and ran it. As you can see in the attached samples the ouput is quite different. There is quite a bit more whitespace between the demo notification and the actual barcode and for WPF the barcode is not centered at 96 dpi (is centered at 97 dpi) as stated in my inital post.

Regarding the whitespace below the CodeText your solution:

<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>builder.SupplementSpace = 0;<br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>builder.CodeTextSpace = 0;
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
does not seem to make a difference. The whitespace below the codetext is still almost as large as the codetext itself and on the WPF result even higher then the codetext.

Best Regards

Hi Johan,

Thank you for writing us back.

This is to update you that we need to investigate the said issues. Investigation has been logged into our system. Following are the details of the related ticket IDs. Our product team will look into it. We will update you with the progress via this forum thread.

BARCODENET-36403: Barcode generated with WinForms application and WPF is different
BARCODENET-36404: Barcode generated with WPF application is not showing code text at the center of the image

Hi,


I have the same problem when I am generating a Code128 barcode.
I have approximately the same code but I set a BarHeight = 0.6 mm.

With the default resolution of 96 dpi, the BarHeight is correct.
But when changing the resolution to 300 dpi, The barcode image becomes wider and I am losing the BarHeight of 0.6 mm.

How can I have a barcode of 300 dpi with BarHeight of 0.6 mm ?

Thank you !

Hi Nicolas,

Thank you for your inquiry.

This is to update you that we are able to notice the said behavior. The information has been forwarded to our product team for further investigation under ticket ID BARCODENET-36405. Our product team will further look into it. We will update you with the progress via this forum thread.

Hi Nicolas,

Thank you for writing us back.

1. Regarding BarHeight of 0.6 mm with barcode of 300 DPI, please use the following code snippet. The sample generates barcode with BarHeight of 0.6 mm. Barcode heigth is 7px that is correct for 300 DPI value.

using (BarCodeBuilder builder = new BarCodeBuilder())
{
//Set the Code text for the barcode. Graphics Unit is millimeter by default;
builder.CodeText = "6040223579";
builder.Resolution = new Aspose.BarCode.Resolution(300, 300, ResolutionMode.Graphics);
builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.Code128;
builder.BarHeight = 0.6f;
builder.BarCodeImage.Save(@"code128_0.6mm_300pdi.tiff", System.Drawing.Imaging.ImageFormat.Tiff);
}

2. Regarding your issue converting Barcode image to PDF, I have split the post and forward it to Aspose.Pdf support team. Where my fellow colleague from Aspose.Pdf support team will look into and update you accordingly. Following is the required link:
https://forum.aspose.com/t/8715

Hi,


Thank you for your answer. The BarHeight seems to be ok. The problem is that the image appears bigger in the pdf file and “lose” the BarHeight previously set.

I’m looking foward with the Aspose.Pdf support team.

Thanks !
Hi Nicolas,

Thank you for your feedback.

It is good to know that the issue with Aspose.Barcode has been resolved. Aspose.Pdf support team will soon update you about their findings/feedback.

Hi Nicolas,

This is to update you that the issues BARCODENET-36403, BARCODENET-36404 have been resolved. Please download the Aspose.BarCode for .Net 16.12.1 from downloads section.

The issues you have found earlier (filed as BARCODENET-36405;BARCODENET-36404;BARCODENET-36403) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.