scala有一个方便的data matrix生成器库吗?我听说过java的zxing,但我找不到一个如何生成数据矩阵图像的实例(最好是ByteArrayOutputStream
)
答案 0 :(得分:0)
找到一个带有简易scala实现的库。在我下面的特定示例中,它将生成一个Data Matrix图像并将其作为scala Array[Byte]
SBT
"net.sf.barcode4j" % "barcode4j" % "2.1"
代码
def generate(data: String) = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import java.awt.Dimension
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.datamatrix.DataMatrixBean
val output = new ByteArrayOutputStream
val canvas = new BitmapCanvasProvider(output, "image/png", 300, BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new DataMatrixBean
barcode.generateBarcode(canvas, data)
canvas.finish
val result = output.toByteArray
output.close
result
}