【问题标题】:iTextSharp datamatrix barcode returns null when setting height/width设置高度/宽度时,iTextSharp datamatrix 条码返回 null
【发布时间】:2013-12-30 04:53:09
【问题描述】:

我正在尝试使用 iTextSharp 创建 2d Datamatrix 条形码。如果我不提供高度或宽度,条形码生成就好了。但是,当我尝试设置条形码的高度和宽度时,它会返回一个空对象。

        BarcodeDatamatrix barcode = new BarcodeDatamatrix
                                        {
                                            Width = 10,
                                            Height = 10
                                        };

        barcode.Generate(barcodeData);
        Image barcodeImage = barcode.CreateImage();
        return barcodeImage;
    }

为什么它返回一个空值,我怎样才能让它设置我的尺寸?

【问题讨论】:

  • 您需要注意两个不同的维度:图像的像素维度和数据矩阵条码的正方形维度。后者只接受规范中定义的特定组合,它会影响您可以在条形码中存储多少数据。

标签: c# itextsharp itext barcode


【解决方案1】:

原来问题是我设置的尺寸小于条形码所需的尺寸。我使用在这里找到的信息:iText datamatrix generation problem 来发现我的错误。

【讨论】:

    【解决方案2】:

    我测试了您的确切代码并且没有任何问题。您实际上在代码中对高度和宽度都使用了 10 吗?当不使用允许的维度之一时,您将得到您提到的空值:http://api.itextpdf.com/itext/com/itextpdf/text/pdf/BarcodeDatamatrix.html#setHeight(int)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-22
      • 2020-11-08
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      相关资源
      最近更新 更多