-1

I am developing an application in android in which i want to print the Image on reciept using thermal printer.

To achive this task i have added the escpos-coffee package in my application.

To print image it is using import java.imageio.BufferedImage, to read image it is using ImageIO.read(file) method both classes are located in rt.jar library which i have externally added in the project.

But when i try to build it, it thorws error :

Error: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)

Before that my sdk version versions were changed, then changed the min sdk to 5.1 and (target & compile skd version to 7.0) then it started throwing.

enter image description here

enter image description here

enter image description here

Any help in detail will be appreciated.

Thank you.

baitmbarek
  • 2,440
  • 4
  • 18
  • 26
Talha
  • 13
  • 7

1 Answers1

0

you need to use SNAPSHOT version com.github.anastaciocintra:escpos-coffee:4.0.0-SNAPSHOT

(SNAPSHOT yet...)

and, after that, implement CoffeImage interface: (CoffeeImageAndroidImpl.java)

import android.graphics.Bitmap;

import com.github.anastaciocintra.escpos.image.CoffeeImage;

public class CoffeeImageAndroidImpl implements CoffeeImage {
    private Bitmap bitmap;

    public CoffeeImageAndroidImpl(Bitmap bitmap) {
        this.bitmap = bitmap;
    }


    @Override
    public int getWidth() {
        return bitmap.getWidth();
    }

    @Override
    public int getHeight() {
        return bitmap.getHeight();
    }

    @Override
    public CoffeeImage getSubimage(int x, int y, int w, int h) {
        return new CoffeeImageAndroidImpl(bitmap.createBitmap(this.bitmap,x,y,w,h));
    }

    @Override
    public int getRGB(int x, int y) {
        return bitmap.getPixel(x, y);
    }
}

and ... print with image like this:

...

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false;

            Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.dog, options);
            RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
            escpos.writeLF("BitonalOrderedDither()");
            // using ordered dither for dithering algorithm with default values
            Bitonal algorithm = new BitonalOrderedDither();
            EscPosImage escposImage = new EscPosImage(new CoffeeImageAndroidImpl(bitmap), algorithm);
            escpos.write(imageWrapper, escposImage);
            escpos.feed(5).cut(EscPos.CutMode.FULL);



...

read more and get github sample on: https://github.com/anastaciocintra/escpos-coffee/issues/9#issuecomment-541343942

PapusCoder
  • 101
  • 1
  • 5