Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

image processing - How to correctly resize barcode generated from libraries in c#

Consider 2 barcodes generated using Bartender Software & Libraries available in Github for generating code 128

  1. I have generated Code 128 barcode using libraries but when I resize them manually from c# it doesn't scan.

  2. I had generated the same value Code 128 in bartender software, I resized and printed it. My scanner scans it perfectly.

I need some help on how do I resize it properly. I tried cloning the libraries and changing the bar width property but couldn't succeed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all install GenCode128 nuget from nuget package manager and then use the below namespaces and code to generate barcode

using GenCode128;
using System;
using System.Drawing;
using System.IO;

    static void Main()
    {
        Image myimg = Code128Rendering.MakeBarcodeImage("Barcode Value", 2, true);
        using (var stream = new MemoryStream())
        {
            myimg.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
            using (var fileStream = File.Create("E:\Barcode.jpeg"))
            {
                stream.Seek(0, SeekOrigin.Begin);
                stream.CopyTo(fileStream);
            }
        }
    }

second parameter in the below code line defines the size of barcode which you can change as per your barcode size requirement.

Image myimg = Code128Rendering.MakeBarcodeImage("Barcode Value", 2, true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...