score:0

Accepted answer

Found a library with easy scala implementation. In my particular example below it will generate a Data Matrix image and return it as scala Array[Byte]

SBT

"net.sf.barcode4j" % "barcode4j" % "2.1"

Code

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      

}

Related Query

More Query from same tag