Generated barcodes too wide

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

Moderator: Alex

IAmByB
Posts: 15
Joined: Thu Jan 19, 2017 2:01 pm

Re: Generated barcodes too wide

Post by IAmByB » Fri Jan 20, 2017 8:05 pm

OK, thank you for your help.

IAmByB
Posts: 15
Joined: Thu Jan 19, 2017 2:01 pm

Re: Generated barcodes too wide

Post by IAmByB » Thu Jan 26, 2017 7:00 pm

Hello,

I have a problem with the code you posted some days before. I tried to create barcodes with it, and I got images looking like barcodes, but I am unable to read them.

I tried to read them with a hand-scanner, with some apps on my Android smartphone, and with the same Vintasoft DLL I use for generation, and I never got a barcode recognized in the picture.

I must mention that I am using a demo version of the DLL, which prints the word DEMO on the barcodes, but for testing reasons, I chantge the picture in Photoshop and remove the DEMO word with a copy of the above part of the barcode.

Did you get readable barcodes with the code you posted ?

Thank you for your help.

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

Re: Generated barcodes too wide

Post by Alex » Fri Jan 27, 2017 11:46 am

Hello,

In your code you are getting the barcode as a graphics path, scale the graphics path and draw the graphics path on a bitmap. Am I right? If yes, please send me your barcode image for analysis. I think you cannot read barcode from image because you distorted the barcode when you scaled the graphics path, i.e. you lose information about bar widths.

Now you are trying to use 72 dpi resolution for your images - your resolution is very low. Could you increase the resolution?

Best regards, Alexander

IAmByB
Posts: 15
Joined: Thu Jan 19, 2017 2:01 pm

Re: Generated barcodes too wide

Post by IAmByB » Mon Jan 30, 2017 2:29 pm

Hello,

I create the barcodes in 72 dpi resolution because I am inserting them into an iTextSharp document, and I undertand that iTextSharp document has a resolution of 72 dpi.
If I used a bigger resolution, I would have to reduce their dimensions to make them fit into the document ?

I'd like to send you a sample of barcode I created (in PNG or PDF format) but I don't see a way to send the sample document to you. How can I do it ?

The code I use was written from the sample you provided me, and is as follows (I removed the part printing the barcode value above it because I do not need it, as I just want the barcode). I also remove the "using Bitmap" part because I must return the image to the function calling this one :

72 is the resolution value

Code: Select all

  public static System.Drawing.Image GetBarcode128WithDimension(ParcelLabelOrientation parcelLabelOrientation, string textForBarcode, int resolution, float barcodeDimension, int codeWidth, int codeHeight)
        {
        
            ImageFormat imageformat = ImageFormat.Png;
            int width = (int)((codeWidth / 10) / 2.54 * 72);
            int height = (int)((codeHeight / 10) / 2.54 * 72);

            Image image = null;

            BarcodeWriter writer = new BarcodeWriter();
            writer.Settings.SetHeight(height - writer.Settings.ValueFont.Height * 2, UnitOfMeasure.Pixels);
            writer.Settings.Barcode = BarcodeType.Code128;
            writer.Settings.Value = textForBarcode;
            using (GraphicsPath barcodePath = writer.GetBarcodeAsGraphicsPath())
            {
                image = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage(image))
                {
                    // draw barcode path
                    RectangleF barcodePathBounds = barcodePath.GetBounds();
                    g.Clear(Color.White);
                    float padding = 5;
                    using (Matrix m = new Matrix((width - padding * 2) / barcodePathBounds.Width, 0, 0, 1, padding, padding))
                        barcodePath.Transform(m);
                    // enable AntiAlias if need!
                    //g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.FillPath(Brushes.Black, barcodePath);
                      }

            return image;
        }

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

Re: Generated barcodes too wide

Post by Alex » Mon Jan 30, 2017 3:26 pm

Hello,
I'd like to send you a sample of barcode I created (in PNG or PDF format) but I don't see a way to send the sample document to you. How can I do it ?
Please send your image with the problem description to support@vintasoft.com.

Best regards, Alexander

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests