![](/img/trans.png)
[英]Erro: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
[英]MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
我正在 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)然后它开始抛出。
任何详细的帮助将不胜感激。
谢谢你。
您需要使用 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.