Size of Code128 barcode changes by value

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

Moderator: Alex

Post Reply
ssj@dativa.dk
Posts: 3
Joined: Fri Feb 04, 2011 12:23 pm

Size of Code128 barcode changes by value

Post by ssj@dativa.dk »

Hi,

Using below code I'm producing a barcode image used for a label - however the size of the image changes with different values
I need to make a fixed size image, how??

Say, using values an image of these size's a returned:
Value="1234567891234000090" : W=1106px, H=203px
Value="123-123-123-1000090" : W=984px, H=197px

String barcodeValue = @"123-123-123-1";

BarcodeWriter barcodeWriter = new BarcodeWriter();

WriterSettings settings = barcodeWriter.Settings;
settings.Barcode = BarcodeType.Code128;
settings.PixelFormat = PixelFormat.Format32bppRgb;
settings.Resolution = 600;
settings.ValueVisible = false;
settings.Value = barcodeValue;
settings.SetWidth(50F, UnitOfMeasure.Millimeters);
settings.SetHeight(8F, UnitOfMeasure.Millimeters);

Image barcodeImage = barcodeWriter.GetBarcodeAsBitmap();

In advance, thanks...
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Size of Code128 barcode changes by value

Post by Alex »

Our barcode writer generates "ideal" barcode image size e.g. when every single bar width = 3px.

General image size is calculated depending on the nearest value specified by SetWidth and SetHeight properties.

Because of that different barcodes (their string value length is meant) cannot be of the same size in pixels.

So you should resize the resulting barcode image using either Graphics.DrawImage method or some resize functions from our Imaging.NET SDK.

--
Sincerely
ssj@dativa.dk
Posts: 3
Joined: Fri Feb 04, 2011 12:23 pm

Re: Size of Code128 barcode changes by value

Post by ssj@dativa.dk »

Thanks Alex,

You say that only value string length is dependant on sizes on resulting barcode image!
Why is the two samples in previous post of different sizes (they have same value length)??

The value of my barcodes will always be exactly 21 chars - but when using hyphens, blanks or possibly other spec. chars the size is changed on resulting image...??

In advance, thanks

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

Re: Size of Code128 barcode changes by value

Post by Alex »

Ok. Let me explain more deeply:

The barcode width depends on codewords count which is utilized to encode your string value (more info you can find in official Code 128 barcode specification).
Here are the codewords for your values:

1. value = "1234567891234000090" (length = 19)
codewords = [MODE_C]|12|34|56|78|91|23|40|00|09|[MODE_B]|0|[CHECK]|[STOP] (length = 14)

2. value = "123-123-123-1000090" (length = 19)
codewords = [MODE_B]|1|2|3|-|1|2|3|-|1|2|3|-|1|0|0|0|0|9|0|[CHECK]|[STOP] (length = 22)

Hereby the second generated barcode image will be 11*8 (88) single bars longer than the first one.
So to inscribe the barcode Nr2 in specified, by SetWidth and SetHeight properties, rectangle its single bar width will be automatically taken
a bit less than for the barcode Nr1. So it is evident that the resulting width in pixels for your barcodes won't concur exactly.

To get these barcode images generated of the same size you should either stretch them up as described above or
draw the lesser image in center of required rectangle (white background preferable).

Best Regards
ssj@dativa.dk
Posts: 3
Joined: Fri Feb 04, 2011 12:23 pm

Re: Size of Code128 barcode changes by value

Post by ssj@dativa.dk »

Alex,

Thank for this very insightfull explanation :-)
This makes it so much clearer

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

Re: Size of Code128 barcode changes by value

Post by Alex »

You are welcome.

--
Best regards
Post Reply