public static void main(String[] args) throws IOException { //String target = "/Users/zhiyu/Desktop/test/aaa_bin.bmp"; String target = "/Users/zhiyu/Desktop/test/test.jpg"; File file = new File(target); BufferedImage image = ImageIO.read(file); drawGraphic(0, 0, image); public static void drawGraphic(int start_x, int start_y, BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); int col = (width - 1) / 8 + 1; String str = ""; byte[] arrayOfByte = new byte[width * height]; int h = 0; //int b1 = 0; int arrindex = 0; //int m = 0; while (h < height) { for (int w = 0; w < width; w++) { arrindex = h * col + w / 8; System.out.println("w:" + w + ", h:" + h); if ((image.getRGB(w, h) & 0xFFFFFF) < 3092271) { int n = arrindex; byte[] arrayOfByte1 = arrayOfByte; arrayOfByte1[n] = (byte) (arrayOfByte1[n] | 128 >> w % 8); } else { int n = arrindex; byte[] arrayOfByte1 = arrayOfByte; arrayOfByte1[n] = (byte) (arrayOfByte1[n] & (128 >> w % 8 ^ 0xFFFFFFFF)); //if ((++h - b1) * col >= 1024 || h == height) { // str = bbbb(aaaaaa(arrayOfByte, m, arrindex - m + 1)); // m = arrindex + 1; // String str1 = "EG " + col + " " + (h - b1) + " " + start_x + " " + (start_y + b1) + " " + str + "\r\n"; // System.out.println(str1); // //b(str1); // b1 = h; // k++; str = toHexString(copy(arrayOfByte, 0, arrindex + 1)); System.out.println(str); static String toHexString(byte[] paramArrayOfbyte) { String str = ""; for (int i = 0; i < paramArrayOfbyte.length; i++) { String hex = Integer.toHexString(paramArrayOfbyte[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; str = str + hex; return str; private static byte[] copy(byte[] paramArrayOfbyte, int start, int length) { byte[] arrayOfByte = new byte[length]; for (int i = 0; i < length; i++) { arrayOfByte[i] = paramArrayOfbyte[start + i]; return arrayOfByte;

在小程序中:

writeLogo2: function (options) { let imgHex1 = "ff00000000001f00000ffe000000003ffffc00000000780000ff80000000003f00001fff80000000ffffff00000000fc0000ffc0000000007f80007fffe0000001ffffff80000001fe0000ffe0000000007f8000fffff0000001ffffffc0000001fe0000fff0000000007f8000fffff8000001fffffff0000003fe0000fffc000000007f8001fffffc000001fffffff8000003fe00007ffe000000007f8001fffffc000000fffffffc000003fe00001fff800000007f8001fffffe0000007fe0fffe000003fe00000fffc00000007f8001ff0fff00000000001fff000003fc000007ffe00000007f8000fc03ff00000000000fff000007fc000003fff00000007f80003001ff800000000007ff800007fc000000fffc0000007f80000000ffc00000000001ff800007fc0000007ffe0000007f80000000ffc00000000000ffc0000ff80000001fff8000007f800000007fe000000000007fc0000ff80000000fffc000007f800000003fe000000000007fc0000ff800000007ffe000007f800000003fe000000000007fc0001ff000000003fff800007f800000003fe000000000007fc0001ff000000000fffc00007f800000001fe000000000007fc0003ff0000000007fff00007f800000001fe00000000000ff80003fe0000000003fff80007f800000001fe00000000001ff80003fe0000000000fffc0007f800000001fe00000000003ff80007fc00000000007ffe0007f800000001fe00000000007ff00007fc00000000003fff0007f800000003fe0000000000fff0000ffc00000000000fffc007f800000003fe0000000001ffe0000ff8000000000007ffe007f800000007fe0000000003ffc0001ff8000000000001fff007f800000007fc000000000fff80001ff0000000000000fffc07f80000000ffc000000003fff00003ff00000000000007ffe07f80000001ff800000000fffe00003fe00000000000003fff07f80000003ff800000007fffe00007fe00000000000000fffc7f80000007ff00000000fffff80007fc000000000000007ffe3f0000000fff00000001fffffc0007fc000000000000003fff0e0000001ffe00000003fffffe000ff8000000000000001fffc00000007ffc00000003fffffe000ff80000000000000007ffe0000000fff800000003ffffff001ff80000000000000003fff0000003fff000000003ffffff001ff00000000000000001fff800000fffe000000001ffffff001ff000000000000000007ffe00007fffc000000001fe01ff803fe000000000000000003fff0000ffffe0000000000000ff803fe000000000000000001fffc001ffffffffc000000000ff803fe3ff8000000000000007ffe001fffffffff800000000ff803fc7fff800000fe0000003fff003fffffffffc00000000ff007fcffffe00003ff8000001fffc01fffffffffe00000000ff007fcfffff8000ffff0000007ffe01fffffffffe00000001ff007fcfffffc001ffffc000003fff01fffffffffe00000001ff00ff8fffffe003ffffe000001fffc0fffffffffc00000001ff00ff87fffff007fffff8000007ffe00ffffffffc00000003fe00ff83fffff007fffffe000003fff00000003ff800000003fe00ff800ffff007ffffff000001fff8000000000000000003fe00ff00003ff807ff7fffc000007ffe000000000000000007fc01ff00000ff807fc1ffff000003fff000000000000000007fc01ff00000ffc07f807fff800001fff80000000000000000ffc01ff000007fc07f800fffc000007ffc0000000000000000ff801ff000007fc07f8001ffc000003fff0000000000000000ff801fe000003fc07f80007fc000001fff8000000000000000ff801fe000003fe07f80007fc000000fffc000000000000001ff003fe000003fe07fc0007fc0000003fff000000000000001ff003fe000003fe07fc0007fc0000001fff800000000000001ff003fe000003fe07fe0007fc0000000fffc00000000000003fe003fe000001fe07ff800ffc00000003ffe00000000000003fe003fe000001fe03fff81ff800000001fff00000000000007fe003fe000001fe03fffffff800000000fffc000000000000ffe003fc000001fe01fffffff0000000007ffe000000000001ffc003fc000001fe00fffffff0000000001fff000000000007ffc003fe000001fe007fffffe0000000000fff80000000003fff8003ff800003fe003fffffc00000000007ffc000000003ffff0003ffff8003fe000fffff800000000003fff01e00001ffffe0003fffffffffe0003ffff000000000001fff87fe000fffffc0003fffffffffc00007ffe0000000000007ffcfffc0ffffff80001fffffffffc000000000000000000003ffeffffffffffe00000fffffffffc000000000000000000001fffffffffffffc000007ffffffff8000000000000000000000fffffffffffff0000001ffffffff00000000000000000000007fffffffffff800000007ffffffe00000000000000000000001ffffffffffc0000000001fffffc00000000000000000000000ffeffffffc00000000000007f80000000000000000000000007fe0ffffe000000000000000000000000000000000000000007ff01fff0000000000000000000000000000000000000000003ff000000000000000000000000000000000000000000000001ff000000000000000000000000000000000000000000000000ff0000000000000000000000000000000000000000000000007e0000000000000000000000000" let imgHex = "fe00000000000c000007fc000000001ffff800000000300000ff00000000003f00001fff000000007ffffe00000000f80000ffc0000000003f00003fffc0000000ffffff00000000fc0000ffe0000000007f80007fffe0000000ffffffc0000001fc0000fff0000000007f8000fffff0000000ffffffe0000001fc00007ff8000000007f8000fffff8000000fffffff0000001fc00003ffe000000007f8001fffffc000000fffffffc000003fc00000fff000000007f8000fffffe0000007e003ffe000003fc000007ff800000007f8000fe07fe00000000001ffe000003fc000003ffe00000007f80007803ff000000000007ff000003fc000001fff00000007f80000001ff800000000003ff000007f8000000fff80000007f80000000ff800000000000ff800007f80000003ffc0000007f800000007fc000000000007f800007f80000001fff0000007f800000007fc000000000007f80000ff800000007ff8000007f800000003fc000000000003f80000ff000000003ffe000007f800000001fe000000000003f80000ff000000001fff000007f800000001fe000000000007f80001ff000000000fffc00007f800000001fe000000000007f80001fe0000000003ffe00007f800000001fe00000000000ff80001fe0000000001fff00007f800000001fe00000000000ff80003fc0000000000fffc0007f800000001fe00000000001ff00003fc00000000003ffe0007f800000001fe00000000003ff00007fc00000000001fff0007f800000001fe00000000007fe00007f8000000000007ff8007f800000003fe0000000000ffc0000ff8000000000003ffc007f800000003fc0000000001ff80000ff0000000000001fff007f800000007fc0000000007ff80001ff00000000000007ff807f800000007fc000000001fff00001fe00000000000003ffc07f80000000ff8000000007ffe00003fe00000000000001ffe03f80000001ff000000003fffc00003fc00000000000000fff83f00000003ff00000000fffff00007fc000000000000003ffc1e00000007fe00000001fffff80007f8000000000000001fff000000000ffc00000001fffffc0007f8000000000000000fff800000003ffc00000003fffffe000ff80000000000000007ffc00000007ff800000003fffffe000ff00000000000000001fff0000001fff000000001ffffff000ff00000000000000000fff8000007ffe000000001ffffff001fe000000000000000003ffc00003fffc000000000f800ff001fe000000000000000001fff00007fff80000000000000ff001fe000000000000000000fff8000ffffffe000000000007f003fc1fc0000000000000007ffc001fffffffff000000000ff003fc3fff000000380000001fff001fffffffff800000000ff003fc7fffc00001fe0000000fff801fffffffffc00000000ff007fc7ffff00007ffc0000007ffc01fffffffffc00000000ff007f87ffff8001ffff0000001fff00fffffffffc00000001fe007f87ffffc003ffffc000000fff807ffffffffc00000001fe007f83ffffe003fffff0000007ffc0007ffffff800000001fe00ff01fffff003fffffc000001fff0000000006000000003fe00ff0000fff007fffffe000000fff8000000000000000003fc00ff00001ff007fc3fff8000007ffc000000000000000003fc00ff00000ff807f80fffc000001ffe000000000000000007f800fe000007f807f801fff000000fff000000000000000007f801fe000007f807f8003ff8000003ffc00000000000000007f801fe000003fc07f8000ff8000001ffe0000000000000000ff001fe000003fc07f80007fc000000fff0000000000000000ff001fe000003fc07f80003fc0000007ffc000000000000000ff001fe000001fc07f80003fc0000003ffe000000000000001fe001fc000001fc07fc0003f80000001fff000000000000001fe001fc000001fe03fe0007f800000007ff800000000000001fe001fc000001fe03ff0007f800000003ffe00000000000003fe003fc000001fe03ffe00ff800000000fff00000000000003fc003fc000001fe01fffffff0000000007ff80000000000007fc003fc000001fe00fffffff0000000003ffc000000000000ffc003fc000001fe007fffffe0000000001ffe000000000003ff8003fc000001fe003fffffe00000000007ff80000000001fff8003fe000001fe001fffffc00000000003ffc000000000ffff0003fff80003fe0007ffff800000000001ffe00000000ffffe0003fffffffffc0000ffff000000000000fff03f80007ffffc0001fffffffffc00001ffc0000000000007ff87ff003fffff00001fffffffff8000000000000000000001ffc7fffffffffe00000fffffffff8000000000000000000000ffe7fffffffff8000003ffffffff00000000000000000000007ff7ffffffffc0000000ffffffff00000000000000000000003ffffffffffe000000001ffffffe00000000000000000000001ffffffffff000000000001ffff000000000000000000000000ffc3fffff800000000000000000000000000000000000000007fe07fff8000000000000000000000000000000000000000003fe00ff80000000000000000000000000000000000000000001fe000000000000000000000000000000000000000000000000fe000000000000000000000000000000000000000000000000fe0000000000000000000000000000000000000000000000003c0000000000000000000000000" console.log(imgHex.length) let buffs = "! 0 200 200 80 1 \n\r" + "EG 25 80 0 0 " + imgHex + "\n\r" + "PRINT" app.globalData.QRPrinter.sendCmd(buffs, true)

"EG 25 80 0 0 " + imgHex + "\n\r"

25 即 col ,    int col = (width - 1) / 8 + 1;

80 图片高度(px)

------

坑爹的QR启锐(建议不要购买这个鬼,厂家提供的支持太差劲), 厂家提供的demo里根本没有说明如何得到图片的数据,  测试了几十种方法才找到这个合适的

小程序 蓝牙 打印 机C PC L指令 图片 打印 问题梳理 本文以汉印HM-T3便携式 打印 机示例讲解 手册中要求需要用ASCII码十六进制字符下发命令,源引自 有赞零售小票 打印 跨平台解决方案 图片 处理 由于 JS 引擎是不能解析 图片 文件的,所以在最初模板中存在 图片 链接时,全部由移动端进行处理,然后进行替换。 图片 处理主要就是下载 图片 图片 压缩,二值图处理, 图片 像素点压缩( 打印 指令要求),每个字节转换成 16 进制,拼接 16 进制字符串。 下载 图片 采用 SDWebImage 进行下载缓存,创建并行队列进行多 EG 5 32 08 08 01FFFFFF8003FFFFFFC007FFFFFFE00FFFFFFFF01FFFFFFFF83FFFFFFFFC7FFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE7FFFFFFFFC3FFFFFFFF81FFFFFFFF00FFFFFFFE007FFFFFFC003FFFFFF8001FFFFFF00 看到很多朋友跟我遇到相似的问题,我把我当初的解决办法贴出来吧。下面的代码是读取24位bmp文件的方法(距离写这个代码有一段时间了,有些注释掉的代码已经忘了干嘛的了) private static string get24BitBmpData(string filePath) Bitmap bmp = new Bitmap(filePath); byte[] bitArray C PC L是目前蓝牙 打印 机流行的指令集,但是C PC L只方便阅读,但是对应的效果图不太直观。 这里有款简单方便好用的工具,可以查看C PC L/TSPL指令,只需要打开工具,把C PC L指令文件命名为"*.hex",然后打开工具, 鼠标双击工具中央就可以查看效果对应的指令效果,如下所示。 如下图,左边为C PC L指令数据,右边为对应的效果图。 1、佳博标签 打印 机编程手册tspl v1.0.7.pdf 2、佳博 打印 机自定义指令手册 v1.0.0.pdf 3、佳博面单 打印 机编程手册c pc l v1.0.3.pdf 4、佳博票据 打印 机编程手册esc v1.0.6.pdf 5、C PC L 指令手册.pdf