【问题标题】:MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O (--min-api 26) 开始
【发布时间】:2020-01-03 10:18:07
【问题描述】:

我正在 android 中开发一个应用程序,我想在其中使用热敏打印机在收据上打印图像。

为了完成这项任务,我在我的应用程序中添加了escpos-coffee 包。

打印它正在使用的图像 import java.imageio.BufferedImage,要读取图像,它使用ImageIO.read(file) 方法,这两个类都位于我在项目中外部添加的rt.jar 库中。

但是当我尝试构建它时,它会出错:

错误:MethodHandle.invoke 和 MethodHandle.invokeExact 只是 从 Android O 开始支持 (--min-api 26)

在此之前我的 sdk 版本已更改,然后将 min sdk 更改为 5.1 并且(目标并将 skd 版本编译为 7.0)然后它开始抛出。

任何详细的帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: java android android-sdk-manager


    【解决方案1】:

    你需要使用SNAPSHOT版本com.github.anastaciocintra:escpos-coffee:4.0.0-SNAPSHOT

    (还有快照...)

    然后,实现 CoffeImage 接口: (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);
        }
    }
    
    

    然后...用这样的图像打印:

    ...
    
                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);
    
    
    
    ...
    

    阅读更多内容并获取 github 示例:https://github.com/anastaciocintra/escpos-coffee/issues/9#issuecomment-541343942

    【讨论】:

      猜你喜欢
      • 2021-04-26
      • 2019-12-05
      • 1970-01-01
      • 2021-03-27
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      • 2019-09-12
      相关资源
      最近更新 更多