Specifiy Barcode Size

2 Answers 30 Views
Barcode
Stefan
Top achievements
Rank 1
Veteran
Stefan asked on 30 Apr 2021, 07:00 AM

Hello,

we are creating a barcode programmatically like it is described here: https://www.telerik.com/forums/generate-barcode-image-programmatically

The problem is, that the barcode itself is a bit small (width) for our purpose.

Our code looks like this:

var barcode = new RadBarcode();
barcode.Width = 900;
barcode.Height = 150;
barcode.Symbology = new Code39();
barcode.Value = "1890";
barcode.LoadElementTree();
var barcodeImage = barcode.ExportToImage(900, 150);
barcodeImage.Save(@"C:\test.png");

But if you look at the attached image (test.png), it has the correct size alright, but not the barcode itself. 

Is there away to give the barcode itself more width?

 

Kind regards.

2 Answers, 1 is accepted

Sort by
1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 May 2021, 09:52 AM

Hi, Stefan,

I have reviewed deeply the settings exposed to the Telerik.WinControls.UI.Barcode.Symbology.Code39 and I have noticed the Stretch property. It controls whether the bars of the barcode should be stretched to fill the space available. I believe that this is the exact setting that you need. Please refer to the following code snippet which result is illustrated in the below screenshot: 

            RadBarcode radBarcode1 = new RadBarcode();
            radBarcode1.Width = 900;
            radBarcode1.Height = 150;
            Telerik.WinControls.UI.Barcode.Symbology.Code39 code39 = new Telerik.WinControls.UI.Barcode.Symbology.Code39();
            code39.Stretch = true;
            radBarcode1.Symbology = code39;
            radBarcode1.Value = "1890";
            radBarcode1.LoadElementTree();
            string fileName = @"..\..\exported.png";
            Image img = radBarcode1.ExportToImage(900, 150);
            img.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            Process.Start(fileName);

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Stefan
Top achievements
Rank 1
Veteran
commented on 04 May 2021, 08:25 AM

Hello Dess,

that is exactly what we were looking for. Thank you very much.

Now we are able to create sharp barcodes in the size(s) we need. :)

Kind regards.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Apr 2021, 08:06 AM
Hello, Stefan, 

Code39 is a barcode symbology which encodes alphanumeric characters into a series of bars. It is of variable length and accepts uppercase letters, as well as numbers. It includes an optional Mod 43 checksum.

The width and height settings seem to be respected in the control and the exported image. However, the Code 39 specification defines 43 characters. That is why the width is no bigger than this in order to keep the barcode valid and the barcode is not stretched in 900 px width as it is specified in the provided code snippet. The width ratio between narrow and wide is not critical, and may be chosen between 1:2 and 1:3: https://en.wikipedia.org/wiki/Code_39 

You can switch the width and height properties and thus the bars will be produced longer.
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Stefan
Top achievements
Rank 1
Veteran
commented on 30 Apr 2021, 09:40 AM

Hallo Dess,

thank you for the clarification.

By 'longer' you mean longer in height? Because height seems to be the only property affected when specifying the barcode size.

The issue for us is, that if we want to have a bigger barcode (in width), we now have to scale the image up, which produces a blurry image. It might not be a problem effectively (for example when printing it out, and scanning it with a barcode scanner), but looks a bit ugly.
Especially because it is also shown in an webapplication, right next to the same barcode we generated with Telerik.MVC, where scaling is no problem and always produces a sharp image...

Kind regards.
Tags
Barcode
Asked by
Stefan
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or