芯烨XP-420B中文乱码

CSDN问答 2021-12-30 03:13:53 阅读数:481

乱码 XP 中文 xp-420b
问题遇到的现象和发生背景

芯烨打印机中文乱码

问题相关代码,请勿粘贴截图
byte[] data2 = DataForSendToPrinterTSC.text(0, 0, "3", 0, 0, 0, "卢本伟的小店");byte[] data = byteMerger(byteMerger(byteMerger(byteMerger(data0, data4), data1), data2), data3);list.add(data);public static byte[] text(int x, int y, String font, int rotation, int x_multiplication, int y_multiplication, String content) { String str = "TEXT " + x + "," + y + ",\"" + font + "\"," + rotation + "," + x_multiplication + "," + y_multiplication + ",\"" + content + "\"\r\n"; byte[] data = strTobytes(str); return data; } private static byte[] strTobytes(String str) { byte[] b = null; byte[] data = null; try { byte[] b = str.getBytes("utf-8"); if (charsetName == null | charsetName == "") { charsetName = "gbk"; } data = (new String(b, "utf-8")).getBytes(charsetName); } catch (UnsupportedEncodingException var4) { var4.printStackTrace(); } return data; }
运行结果及报错内容

卢本伟的小店 乱码

我的解答思路和尝试过的方法

各种编码都用过 gb2312 gbk utf-8 机器默认是gbk

我想要达到的结果

怎样才不会乱码




采纳答案:

编解码处理一下。

img



其他答案2:
byte[] data2 = DataForSendToPrinterTSC.text(0, 0, "3", 0, 0, 0, URLEncoder.encode("卢本伟的小店", "utf-8")); byte[] data3 = DataForSendToPrinterTSC.print(1); byte[] data = byteMerger(byteMerger(byteMerger(byteMerger(data0, data4), data1), data2), data3); list.add(data);

img


感觉官方有特定的写法 单SDK里没有

版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7612912