please any help ... I want to print receipt in a thermal printer using android and if the height of image larger then 350 PX this error show "height is too large"
My Code :
private void printVoucher(){
ArrayList<Printable> printables = new ArrayList<>();
Picasso.get()
.load("Path Image")
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
printables.add(new ImagePrintable.Builder(bitmap).setNewLinesAfter(0).build());
//printing.print(printables);
Printooth.INSTANCE.printer().print(printables);
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
}
Error :
E/decodeBitmapĀ error: height is too large
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mirasoft.mirasoftapperp, PID: 20979
java.lang.NullPointerException
at com.mazenrashed.printooth.data.DefaultPrintingImagesHelper.getBitmapAsByteArray(DefaultPrintingImagesHelper.kt:8)
at com.mazenrashed.printooth.data.printable.ImagePrintable.getPrintableByteArray(ImagePrintable.kt:16)
at com.mazenrashed.printooth.utilities.Printing.printPrintables(Printing.kt:66)
at com.mazenrashed.printooth.utilities.Printing.access$printPrintables(Printing.kt:13)
at com.mazenrashed.printooth.utilities.Printing$initDeviceCallback$1.onDeviceConnected(Printing.kt:43)
at com.mazenrashed.printooth.utilities.Bluetooth$ConnectThread.lambda$run$0$Bluetooth$ConnectThread(Bluetooth.java:324)
at com.mazenrashed.printooth.utilities.-$$Lambda$Bluetooth$ConnectThread$PrUWb5GXkpw9YbMT2riXHliWDR8.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I found a workaround that allowed me to use this printing library by splitting the image into smaller images.
Bitmap.createBitmap
is used here to crop the image and it takes arguments:original bitmap
,x
,y
,width
,height
The image printed just fine even tho I split it up.