41.4. 使用 Java DSL

首先,您必须初始化 barcode 数据 fomat 类。您可以使用默认构造器或参数化之一(请参阅 JavaDoc)。默认值为:

参数默认值

image type (BarcodeImageType)

PNG

width

100 px

height

100 px

encoding

UTF-8

Barcode 格式(BarcodeFormat)

QR-Code

// QR-Code default
DataFormat code = new BarcodeDataFormat();

如果要使用 zxing hints,您可以使用 BarcodeDataFormat 实例的 'addToHintMap' 方法:

code.addToHintMap(DecodeHintType.TRY_HARDER, Boolean.true);

有关可能的提示信息,请参阅 xzing 文档。

41.4.1. marshalling

from("direct://code")
  .marshal(code)
  .to("file://barcode_out");

您可以使用以下测试类调用路由:

template.sendBody("direct://code", "This is a testmessage!");

您应该在该镜像的 'barcode_out' 文件夹中找到:

image