3

我遇到了烧烤条形码库的问题。我正在尝试创建一个简单的 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#" />

这将输出以下图像:

烧烤生成条码 10047846

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

在此处输入图像描述

这是我从barcode-generator.org 得到的:

在此处输入图像描述

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

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

4

3 回答 3

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#" />
于 2015-02-04T22:40:51.263 回答
0

看起来图像的条形宽度比示例大。将条形宽度设置为 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>
于 2015-02-04T22:05:15.667 回答
0

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

在此处输入图像描述

于 2015-02-04T22:18:00.177 回答