I'm trying to print qr code like image, on a thermal pos bluetooth printer in android studio,the printer is connected - bluetooth, I can print the text and image as Drawable, but I can't I can't print the image from url, I would be grateful if someone can help.
i want to send qr code as image to printer
URL := 'http://www.examples.com/code_1.png';
I use this function (Android studio), for printing
try {
myBitSlika = getBitmapFromURL("https://examles.com/temp/code_nn.png") ;
} catch (Exception e) {
Log.e("APP", "url image::", e);
}
BluetoothConnection connection = BluetoothPrintersConnections.selectFirstPaired();
if (connection != null)
{
EscPosPrinter printer = new EscPosPrinter(connection, 203, 48f, 32);
final String text = ""[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer,myBitSlika )+ "</img>\n" +
"[L]\n" +
"[L]" + df.format(new Date()) + "\n" +
"[C]================================\n" +
"[L]<b>Effective Java</b>\n" +
"[L] 1 pcs[R]" + nf.format(25000) + "\n" +
"[L]<b>Headfirst Android Development</b>\n" +
"[L] 1 pcs[R]" + nf.format(45000) + "\n" +
"[L]<b>The Martian</b>\n" +
"[L] 1 pcs[R]" + nf.format(20000) + "\n" +
"[C]--------------------------------\n" +
"[L]TOTAL[R]" + nf.format(90000) + "\n" +
"[L]DISCOUNT 15%[R]" + nf.format(13500) + "\n" +
"[L]TAX 10%[R]" + nf.format(7650) + "\n" +
"[L]<b>GRAND TOTAL[R]" + nf.format(84150) + "</b>\n" +
"[C]--------------------------------\n" +
"[C]<barcode type='ean13' height='10'>202105160005</barcode>\n" +
"[C]--------------------------------\n" +
"[C]Thanks For Shopping\n" +
"[C]https://kodejava.org\n" +
"[L]\n" +
"[L]<qrcode>https://kodejava.org</qrcode>\n";
printer.printFormattedText(text);
I use this feature to retrieve an image from the internet
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
Log.e("APP", "save image", e);
return null;
}
}
if instead of myBitSlika, I put it to take a picture with drawable directory, print without problems, (PrinterTextParserImg.bitmapToHexadecimalString(printer,this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.code_232,DisplayMetrics.DENSITY_LOW, getTheme()))
final String text = "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer,this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.code_232,DisplayMetrics.DENSITY_LOW, getTheme())) + "</img>\n" +