Writing barcode content as a label under a barcode using the Java Zxing API

I am using zxing api to create a barcode. But when creating, I cannot write the contents of the barcode as a label below the barcode.

conclusion - enter image description here

exit required - enter image description here

The code for generating these barcodes is as follows -

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

public class BarcodeTesting {

	private static void wrtieToStream(BitMatrix bitMatrix) {
		try {
			MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("hello" + ".png")));
			System.out.println( " Barcode Generated.");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private BitMatrix generateBitMatrix(String content, BarcodeFormat format, int width, int height) {
		MultiFormatWriter writer = new MultiFormatWriter();
		BitMatrix bitMatrix = null;
		try {
			bitMatrix = writer.encode(content, format, width, height);
		} catch (WriterException e) {
			e.printStackTrace();
		}
		return bitMatrix;
	}

	public static void main(String[] args) {
		BarcodeTesting obj = new BarcodeTesting();
		BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
		BitMatrix bitMatrix = obj.generateBitMatrix("MY QR Code 123", barcodeFormat, 24, 24);
		// String formatString = format.toString();
		wrtieToStream(bitMatrix);
	}
}
Run codeHide result
+4
source share
2 answers

QRCode , , zxing - . . , QRCode. .

+2

@tobltobs. , zxing api, , . , , - . - String . enter image description here

0

All Articles