I am working with a bluetooth thermal printer and was able to print normal text and invoice's as well. But i am not able to print barcodes.
I am generating barcode with ZXING library
OutputStream os = mBluetoothSocket.getOutputStream();
String text = mEditText.getText().toString();
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
BitMatrix bitMatrix = multiFormatWriter.encode(text,BarcodeFormat.CODE_128,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
os.write("Hello".getBytes()); //Prints Hello
How can i print the bitmap using the same logic ?
I have tried some codes like
int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);
byte[] byteArray = byteBuffer.array();
os.write(byteArray);
But this gives a blank print and roll keep rolling
I am using Godex-MX30 printer
You need to tell the printer that you are sending an image to print and specify how to print it.
Typically this is done with ESC/POS codes. Most printers like this use ESC/POS codes.
ESC * is how that is specified. You can look at the many examples in this questions java code or in this one's solution as well.
For more information, see Seiko Epson reference.
Not sure about this printer, but many of thermal receipt printers have support for creating and printing barcodes also using Esc/Pos Code. You could try something like this.