【问题标题】:How to correctly resize barcode generated from libraries in c#如何正确调整从 C# 中的库生成的条形码大小
【发布时间】:2021-04-07 13:14:31
【问题描述】:

  1. 我已经使用库生成了 Code 128 条形码,但是当我从 c# 手动调整它们的大小时,它不会扫描。

  2. 我在调酒师软件中生成了相同的值 Code 128,我调整了大小并打印了它。我的扫描仪完美扫描。

我需要一些有关如何正确调整其大小的帮助。我尝试克隆库并更改条形宽度属性,但未能成功。

【问题讨论】:

  • 条码打印机可以在使用 ZPL 命令时本地调整代码大小。你到底在做什么。如果您正在生成位图,最好告诉生成器将它们生成到您需要的大小。这个问题缺乏合适的信息来回答
  • 称为像素提示
  • @00110001 我已经通过了我需要的宽度,但是由于大数据,库没有调整大小,比如.Width=50,但它会生成大约 180 px,如果我传递小数据,它会生成我想要的宽度
  • @Charlieface 你能帮我看看我该怎么做吗,试着在谷歌上搜索,但没有找到任何相关的文章。

标签: c# image-processing zxing code128 bartender


【解决方案1】:

首先从 nuget 包管理器安装 GenCode128 nuget,然后使用下面的命名空间和代码生成条形码

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);
            }
        }
    }

下面代码行中的第二个参数定义了条码的大小,您可以根据您的条码大小要求进行更改。

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

【讨论】:

  • 嗨 Bhavik,我已经尝试过 n 测试了 nuget 上几乎所有可用的条形码库,但所有的宽度都超出了我的需要。请在发布答案之前仔细阅读。
猜你喜欢
  • 2011-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-02
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
相关资源
最近更新 更多