你需要使用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