Ticket T1279894
Visible to All Users

ASP.NET BarCode 128

created 5 days ago

Hi!

I am attempting to generate a barcode 128. If I leave barCode.AutoSize = true; the barcode works great. I can successfully scan it.
However if I set barCode.AutoSize = false; then the bar code image comes across as shown in the attached image. This cannot be scanned. How can I change the barcode height and width to generate a barcode I can use?

Thank you.,
jacks@dlcoffee.com

Code
private void BarCode_Test1(PdfGraphics graph, string CodeText, int xAxis, int yAxis, int Width, int Height) { BarCode barCode = new BarCode(); barCode.Symbology = Symbology.Code128; barCode.Options.Code128.Charset = Code128CharacterSet.CharsetB; barCode.Options.Code128.ShowCodeText = true; barCode.CodeText = CodeText; // Example: "JOB109379"; barCode.BackColor = System.Drawing.Color.White; barCode.ForeColor = System.Drawing.Color.Black;![Clipboard-File-1.png](/attachment/file/b771cefe-5eac-4db9-88fe-fca33ec0fb19) barCode.RotationAngle = 0; barCode.DpiX = 72; barCode.DpiY = 72; barCode.AutoSize = false; barCode.ImageWidth = Width; barCode.ImageHeight = Convert.ToInt32(Width * .333); // Height; barCode.Module = 1f; graph.DrawImage(barCode.BarCodeImage, new PointF(xAxis-200, yAxis)); }
Comments (3)
Sasha (DevExpress Support) 4 days ago

    Hello Jack,

    Thank you for the code snippet. I reviewed it but didn't find an obvious reason for the issue. If I understand correctly, you are adding the generated BarCodeImage to a PDF file:

    C#
    graph.DrawImage(barCode.BarCodeImage, new PointF(xAxis-200, yAxis));

    If so, would you please ensure that you use correct DPI when you are calling the AddToPageForeground method:

    C#
    graph.AddToPageForeground(page, 72, 72);

    If it doesn't help, please modify the attached project to illustrate the issue or share your own project where the issue is reproducible.

    I look forward to your results.

    JS JS
    Jack Slyfield a day ago

      Hi.

      I have added the created PNG files of two barcode's, as well as a PDF file.
      I attempted to add all projects files in a zip file but it was to large. I have added the barcode ASPX and the barcode.cs file as well as the designer.cs.

      The project creates two bar codes. The first uses autosize and it works fine. I can successfully scan the bar code. The second changes the height and width using the ImageHeight and the ImageWidth properties. This one cannot be scanned. I will need to change the Height and Width when I generate the bar codes in the target project.

      Note that the project saves the files into directory C:\work. This may need to be changed if you run the project.

      Please review and let me know how I can change the bar code dimensions and scan the results.

      Thank you,
      Jack Slyfield
      jacks@dlcoffee.com

      Sasha (DevExpress Support) 8 hours ago

        Hello Jack,

        Thank you for the sample project. I now see the issue. I believe that it occurs because you set the Unit property to Pixel and the resulting image is too small (150x30 px). Is it possible to increase the image size? If not, you can try the following solution: Set the AutoSize property to true and save a temp image. Then, resize the large image in the following manner:

        C#
        barCode.Save("temp.png", System.Drawing.Imaging.ImageFormat.Png); var image = Image.FromFile("temp.png"); var finalImage = new Bitmap(image, new Size(150, 30)); finalImage.Save("final.png");

        Please test this solution and let me know if it helps.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.