【问题标题】:Why is the Barbecue Barcode library generating a different image from other Barcode generators?为什么烧烤条码库生成的图像与其他条码生成器不同?
【发布时间】:2015-02-05 06:40:51
【问题描述】:

Barbecue Barcode Library 有问题。我正在尝试创建一个简单的 code128 条码,但我得到的图像与我从其他在线(即http://barcode-generator.org)和桌面(即 Zing)条码生成器获得的图像不同。

这是我正在使用的 ColdFusion 代码:

<cfscript>
    LOCAL.BarcodeData = "10047846";
    LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
    LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128(LOCAL.BarcodeData);
    LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
    LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
    LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
    LOCAL.BarcodeImagePath =
        "C:\temp_\barcode-" & LOCAL.BarcodeData & ".jpg";
    ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
<cfimage action="writeToBrowser" source="#LOCAL.BarcodeImagePath#" />

这会输出以下图像:

然而,这是我从 Zing 桌面程序中得到的:

这是我从barcode-generator.org 获得的信息:

现在,我对大小、缩放等没有任何问题。但是,您可以很容易地看出烧烤生成的图像有很大不同 - 只需看看前几条。

为什么会这样?这是烧烤错误还是我做错了什么?

【问题讨论】:

  • 为什么用 ColdFusion 标记?
  • @ScottStroz 因为我正在使用 ColdFusion 调用库并生成图像。
  • '211214' 模式以烧烤代码开头是 CODE128B 的开始。另外两个“211232”是 CODE128C 的 START。两者都有效。

标签: coldfusion barcode barbecue


【解决方案1】:

不确定这本身就是“答案”,但是,当我将代码更改为使用 Code128C 格式时,图像按预期出现。我只需要调整大小就可以得到我需要的大小:

代码:

<cfscript>
    LOCAL.BarcodeData = "10047846";
    LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
    LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128C(LOCAL.BarcodeData);
    LOCAL.Barcode.setDrawingText(false);
    LOCAL.Barcode.setDrawingQuietSection(false);
    LOCAL.Barcode.setBarWidth(1);
    LOCAL.Barcode.setBarHeight(30);
    LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
    LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
    LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
    LOCAL.BarcodeImagePath =
        "C:\temp_\barcode-" & LOCAL.BarcodeData & ".jpg";
    ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
<cfimage action="writeToBrowser" source="#LOCAL.BarcodeImagePath#" />

【讨论】:

    【解决方案2】:

    您的图片的条形宽度看起来比示例中的要大。将条形宽度设置为 1 px。在生成条形码之前添加LOCAL.Barcode.setBarWidth(1);

    <cfscript>
      LOCAL.BarcodeData = "10047846";
      LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
      LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128(LOCAL.BarcodeData);
      LOCAL.Barcode.setBarWidth(1); // decrease the width of the bars
      LOCAL.Barcode.setBarHeight(50); // if you want a taller barcode like the examples
      LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
      LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
      LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
      LOCAL.BarcodeImagePath = gettempDirectory()& "\barcode-" & LOCAL.BarcodeData & ".jpg";
    ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
    </cfscript>
    

    【讨论】:

      【解决方案3】:

      我用条形码扫描仪扫描了它,所有三个图像都读取相同的字符串“10047846”。对于条形码,我使用 CFBarbecue (http://cfbarbecue.riaforge.org/),这是一个用于烧烤的 ColdFusion 包装器。使用相同的字符串,下面是我使用 CFBarbecue 生成的图像。

      【讨论】:

      • 我也在使用 CFBarbecue,但我想验证这不是 CFC 的问题,所以我编写了这个简单的应用程序来尝试一下。
      • 很高兴知道它有效。我只是想取悦客户,我生成的条形码对他们不起作用。
      猜你喜欢
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      相关资源
      最近更新 更多