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
Codeprivate 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;
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));
}
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:
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:
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.
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
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:
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.