.net生成條形碼


1、.net 標准庫(.net standard 2.0)

  Nuget添加引用:ZXing.Net生成條形碼,ZXing.Net.Bindings.ImageSharp生成圖片

public static string GenerateBarcode(string barcode)
        {
            var barcodeWriter = new ZXing.ImageSharp.BarcodeWriter<Rgba32>
            {
                Format = BarcodeFormat.CODE_128,
                Options = new EncodingOptions
                {
                    Height = 100,
                    Width = 200,
                    PureBarcode = false
                }
            };
            var name = Guid.NewGuid().ToString().Replace("-", "") + ".png";
            var localRes = AppSettingsHelper.LocalRes;
            var filePath = localRes + name;
            using (var image = barcodeWriter.Write(barcode))
            {
                image.Save(filePath);
            }

            var resUrl = AppSettingsHelper.ResUrl;
            var url = filePath.Replace(localRes, resUrl);
            return url;
        }

2、.net framework 4.6.1

public static string GenerateBarcode(string barcode)
        {
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.CODE_128;
            writer.Options = new ZXing.Common.EncodingOptions
            {
                Height = 100,
                Width = 200,
                PureBarcode = false
            };

            Bitmap bitmap = writer.Write(barcode);
            var fileName = Guid.NewGuid().ToString().Replace("-", "") + ".png";
            var localRes = AppSettingsHelper.LocalRes;var filePath = localRes + fileName;
            bitmap.Save(filePath);
            var resUrl = AppSettingsHelper.ResUrl;
            var url = filePath.Replace(localRes, resUrl);
            return url;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM