Barcode xDimension ignoring units and/or decimals


#1

I’m using Compact Framework 3.5 and it looks like the xDimension property of the barcode is not working accordingly to the GraphicsUnit property. This has already been reported and fixed far back in the past, which makes me feel a bit confused. The fact is the xDimension property seems to ignore the GraphicsUnit property value, and also looks like ignoring any decimal values.

With the following code it gives identical images using 2.5, 2.6, 2.7, 2.8, 2.9 or 3.0 values in xDimension property:

        Aspose.BarCode.BarCodeBuilder barCodeBuilder = new Aspose.BarCode.BarCodeBuilder("1234567890123456789", Aspose.BarCode.Generation.EncodeTypes.Code128)
        {
            Resolution=new Aspose.BarCode.Resolution(600,600, Aspose.BarCode.ResolutionMode.Customized),
            // Set the bar height to 3 points and measuring unit of barcode to point
            BarHeight = 53.0f,
            xDimension = 2.5F,
            GraphicsUnit = GraphicsUnit.Millimeter
        };
        pictureBox1.Image = barCodeBuilder.GetOnlyBarCodeImage();

Moreover, GraphicsUnit property affects all measures except xDimension, this means it will produce identical images no matter the GraphicsUnit configured.

Thanks in advance.


#2

@albert.ruiz,

We have executed the code snippet shared by you and able to generate the barcode images. The generated barcode images are attached for your reference. Can you please have a look and explain a bit more about the issue.

test_compact_framework.zip (253.9 KB)


#3

@albert.ruiz,

We have further investigated the issue. Please note that XDimension property has pixel sampling and will be rounded to the nearest value in pixels. So, when DisplayUnit is set to millimeters, formula on the backend converts it to pixels and value in pixels will be rounded to the nearest integer. The reason behind this conversion is that we can not draw blurred barcode image and as a result different float xDimension produces the same barcodes.

Furthermore when picture is saved with methods

BarCodeBuilder.Save
BarCodeBuilder.GenerateBarCodeImage

xDimension property works as expected. As a workaround please use the following code snippet instead of using GetOnlyBarCodeImage method.

barCodeBuilder.CodeLocation = CodeLocation.None;
barCodeBuilder.Margins.Set(0);
pictureBox1.Image = barCodeBuilder.GenerateBarCodeImage();

An issue with ID BARCODENET-36908 has been logged into our system for further investigation on GetOnlyBarCodeImage method malfunctioning. We will update you here once there is some information or a fix version available in this regard.


#4

@ikram.haq,

Thank you for your answer. I understand when using DisplayUnit = pixels or point, the value should contain no decimals. But when using DisplayUnit = millimeters or inches, using xDimension = 2.5 and 2.9 mm should produce different images, because that value shouldn’t be rounded before converting it to pixels (or whatever unit is used as basic drawing unit to create the code image), but after.

Edit: for further explaining, I’m generating barcodes at 180 dpi, thus 2.5mm ~ 18 pixels, and 2.9mm ~ 21 pixels; that’s why the images they produce should be different.
Additionally, shouldn’t be xDimension in pixels an absolute measure? I mean, if I set xDimension to N pixels, shouldn’t I get a barcode whose thinnest bar has a width of exactly N pixels? Thank you in advance.


#5

@albert.ruiz,

Thank you for writing us back. We have noted your comments. We will update you soon with the details.


#6

Hello, there has been no update on this since June. Any updates on BARCODENET-36908? Thank you in advance.


#7

@albert.ruiz,

Please use the code snippet given below to specify barcode dimensions in millimeter. Please use the latest version of Aspose.Barcode for .NET for testing.

using (BarCodeGenerator gen = new BarCodeGenerator(EncodeTypes.Code128, "1234567890123456789"))
{
    gen.Resolution = 600;
    gen.BarHeight.Millimeters = 53;

    gen.XDimension.Millimeters = 2.5f;
    gen.Save("code128_2_5.png");

    gen.XDimension.Millimeters = 2.8f;
    gen.Save("code128_2_8.png");

    gen.XDimension.Millimeters = 3.0f;
    gen.Save("code128_3_0.png");
}

We hope that this fixed the issue that you were facing. Please feel free to contact us if additional information is required.


#8

Hello @muhammadahmad,
I’m sorry that won’t work. As said above, I’m using the 3.5 COMPACT Framework version; there is no “Millimeters” property under XDimension (actually xDimension’s type is float), thus I can’t specify the units as you suggest.


#9

@albert.ruiz,

New Barcode generation API has been added to Aspose.Barcode for .NET. This scenario was tested using the new API on the compact framework. Please share the exception that you receive when you execute the following code snippet so that we can investigate the issue further. Please use the latest version of Aspose.Barcode for .NET for testing.

using (BarCodeGenerator gen = new BarCodeGenerator(EncodeTypes.Code128, "1234567890123456789"))
{
    gen.Resolution = 600;
    gen.BarHeight.Millimeters = 53;

    gen.XDimension.Millimeters = 2.5f;
    gen.Save("code128_2_5.png");

    gen.XDimension.Millimeters = 2.8f;
    gen.Save("code128_2_8.png");

    gen.XDimension.Millimeters = 3.0f;
    gen.Save("code128_3_0.png");
}