Save barcode image to stream in Java

I try to save a barcode made by Aspose.barcode to a stream conform documentation.

Conform the documentation I should use save(outStream, BarCodeImageFormat.Jpeg), but only inputstream is available as parameter.

I get this (compilation) error in code on the save method: The method save(InputStream, int) in the type BarCodeBuilder is not applicable for the arguments

(ByteArrayOutputStream, int)

The constructor ByteArrayOutputStream(ByteArrayOutputStream) is undefined

Now I write the image to disk and read it from disk. But I want to use it as a stream and copy the image of the barcode in a Word document.

my code is:

BarCodeBuilder bcdbuilder =  **new**  BarCodeBuilder();

//set code text

bcdbuilder.setCodeText(bcdWaarde);

//set symbology type

bcdbuilder.setSymbologyType(Symbology. *Code128* );

bcdbuilder.setxDimension(0.5f);

// Border will not be visible

bcdbuilder.setBorderVisible( **false** );

bcdbuilder.save( **new**  ByteArrayOutputStream(dstStream), com.aspose.barcode.BarCodeImageFormat. *Png* );

Hi Ernst,


Thanks for your inquiry. Did you try using the latest version of Aspose.BarCode for Java 5.4.0? Because you can use the following source code below:


e.g
Sample code:

BarCodeBuilder builder =  **new**  BarCodeBuilder();

// set symbology of the barcode

builder.setSymbologyType(com.aspose.barcode.Symbology. *Code128* );

// set code text

builder.setCodeText("123456");

builder.setxDimension(0.5f);

// Border will not be visible

builder.setBorderVisible( **false** );

//initialize ByteArrayOutputStream object

ByteArrayOutputStream outStream =  **new**  ByteArrayOutputStream();

// save barcode image

builder.save(outStream, com.aspose.barcode.BarCodeImageFormat. *Jpeg* );

ByteArrayInputStream srcStream =  **new**  ByteArrayInputStream(outStream.toByteArray());

// load the bar code image stream

BarCodeReader reader =  **new**  BarCodeReader(srcStream);

// recognize the bar code image

**while**  (reader.read())

{

System. *out* .println("Barcode Found: " + reader.getCodeText());

}

reader.close();

You can download the latest build of Aspose.BarCode for Java 5.4.0 from here:
http://www.aspose.com/community/files/72/java-components/aspose.barcode-for-java/default.aspx

Please let me know in case of further assistance or questions.

Thank for the answer.

I have downloaded the latest version of barcode and now it works.

Hi Ernst,


Thanks for the information. It is great to hear that the issue has been resolved. Please feel free to ask if you have any other query in the future.