Android打印机无法使用热敏打印机打印Logo。
创始人
2024-10-07 03:00:47
0
  1. 确定打印机支持Logo打印。
  2. 使用BitmapFactory将Logo转换为位图格式。
  3. 将位图转换为字节数组,并通过打印指令发送给打印机。

以下是代码示例:

private void printLogo() {

// 确定打印机支持Logo打印
byte[] cmd = new byte[]{0x1D, 0x28, 0x6B, 0x03, 0x00, 0x01, 0x02};
mPrinter.write(cmd);

// 将Logo转换为位图格式
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
byte[] data = PrintUtils.bitmap2Bytes(bmp);

// 将位图数据发送给打印机
byte[] printImageData = new byte[]{0x1D, 0x2A, 0x57, (byte) (bmp.getWidth() / 8 % 256), (byte) (bmp.getWidth() / 8 / 256), (byte) (bmp.getHeight() % 256), (byte) (bmp.getHeight() / 256)};
mPrinter.write(printImageData);
mPrinter.write(data);

}

// 将Bitmap转换为字节数组 public static byte[] bitmap2Bytes(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); }

相关内容

热门资讯

三分钟辅助!cloudpoke... 三分钟辅助!cloudpoker怎么开挂,来玩app破解版,绝活教程(有挂辅助)1、点击下载安装,c...
第1分钟辅助!德州局HHpok... 您好,wepoker私人局俱乐部怎么进这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527...
第9分钟辅助!wpk是真的还是... 第9分钟辅助!wpk是真的还是假的,来玩app破解,窍门教程(有挂总结)1、金币登录送、破产送、升级...
2分钟辅助!hhpoker可以... 2分钟辅助!hhpoker可以开挂吗,拱趴大菠萝挂怎么安装,练习教程(有挂头条)1、起透看视 拱趴大...
两分钟辅助!fishpoker... 两分钟辅助!fishpoker透视底牌,wepoker透视最简单三个步骤,演示教程(竟然有挂)1、金...
第三分钟辅助!hhpoker作... 第三分钟辅助!hhpoker作弊码,wepoker怎么看底牌,手段教程(有挂教程)wepoker怎么...
第9分钟辅助!aapoker辅... 第9分钟辅助!aapoker辅助器是真的吗,aa poker辅助包,绝活儿教程(有挂助手)1.aap...
第2分钟辅助!wepoker免... 第2分钟辅助!wepoker免费透视脚本,wepoker免费透视,指南教程(有挂细节)1、wepok...
第六分钟辅助!steampok... 第六分钟辅助!steampokermaster辅助,sohoopoker辅助,经验教程(有挂透视)1...
6分钟辅助!约局吧德州有挂吗,... 6分钟辅助!约局吧德州有挂吗,epoker有透视吗,项目教程(真是有挂)1、首先打开约局吧德州有挂吗...