anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
282 stars 74 forks source link

BitonalOrderedDither crash #59

Closed SerggioC closed 3 years ago

SerggioC commented 3 years ago

I dont know what kind of issue this should be in or why is it happening, but here it is. I got this crash report on crashlytics log from BitonalOrderedDither:

Fatal Exception: java.lang.RuntimeException
Caused by java.lang.NoSuchMethodError
No virtual method ints(II)Ljava/util/stream/IntStream; in class Ljava/util/Random; or its super classes (declaration of 'java.util.Random' appears in /system/framework/core-libart.jar)
com.github.anastaciocintra.escpos.image.BitonalOrderedDither.<init> (BitonalOrderedDither.java:70)
com.github.anastaciocintra.escpos.image.BitonalOrderedDither.<init> (BitonalOrderedDither.java:84)

Any ideas what is?

Thank you!

anastaciocintra commented 3 years ago

No @SerggioC,

Is this reproducible? Can you share the piece of code ?

SerggioC commented 3 years ago

Hi, This only happened once as it's reported by Firebase Crashlytics, this never occured in my tests. Can't find out why the stacktrace refers Random and IntStream...

I have this code to print images:

RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
Bitonal algorithm = new BitonalOrderedDither();
EscPosImage escposImage = new EscPosImage(new CoffeeImageAndroidImpl(bitmap), algorithm);
escposCoffeePrinter.write(imageWrapper, escposImage);
anastaciocintra commented 3 years ago

is this on android?

SerggioC commented 3 years ago

Yes it's on andoid.

anastaciocintra commented 3 years ago

ok, I've reproduced it wright now on desenv / with api 19 kitkat. and api 21 too I don't know why yet but it can work with threshold, an simplier algorithm

//            Bitonal algorithm = new BitonalThreshold();
            Bitonal algorithm = new BitonalOrderedDither();

I don't know the min api sdk version to espos-coffee work properly, need to test! but 19 kitkat can work with this caveats (BitonalOrderedDither();)

anastaciocintra commented 3 years ago

change

Bitonal algorithm = new BitonalOrderedDither();

by this

Bitonal algorithm = new BitonalThreshold();
SerggioC commented 3 years ago

Great catch! I will try the change.

As I see in the sample, using BitonalThreshold the resulted printed image will be smaller with "compacted" pixels right? Is that the only difference? I'm on min SDK 19 for the project.

Thank you.

anastaciocintra commented 3 years ago

good, 19 is ok for me! the difference between threshold and ordered diter is that with the ordered BitonalOrderedDither, the image printed have a grey-scale sensation for whom is seeing, and threshold algo print a image in black-white (more traditional way). But the size of printing is the same.

I will focus on discover exactly witch android api/sdk min version is necessary for escpos-lib (next activities).

anastaciocintra commented 3 years ago

hi @SerggioC the newest release v4.0.3 is now offering BitonalOrderedDither on api level 19.

[], Marco

SerggioC commented 3 years ago

Thanks @anastaciocintra. I'll update the version. Until now, after changing to BitonalThreshold, I didn't see any more crashes. Issue can be closed maybe.