esp-pos打印图片和二维码

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
data[0] = 0x1D;data[1] = 0x76;data[2] = 0x30;data[3] = 0x00;data[4] = (byte) w;// xLdata[5] = (byte) (w >> 8);// xHdata[6] = (byte) h;data[7] = (byte) (h >> 8);int k = targetBmp.getWidth() * targetBmp.getHeight();int[] pixels = new int[k];targetBmp.getPixels(pixels, 0, targetBmp.getWidth(), 0, 0, targetBmp.getWidth(), targetBmp.getHeight());int j = 7;int index = 8;for (int i = 0; i < pixels.length; i++) { int clr = pixels[i]; int red = (clr & 0x00ff0000) >> 16; int green = (clr & 0x0000ff00) >> 8; int blue = clr & 0x000000ff; if (j == -1) { j = 7; index++; } data[index] = (byte) (data[index] | (RGB2Gray(red, green, blue) << j)); j--;}
buffer.write(data);
byte[] n1 = new byte[]{29, 104, 55};
byte[] n2 = new byte[]{29, 119, 2};
byte[] n3 = new byte[orderNumberStr.length()];
int i = 0;
while (i * 2 < orderNumberStr.length()) {
    n3[i] = Byte.valueOf(Byte.parseByte(orderNumberStr.substring(i * 2, i * 2 + 2))).byteValue();
    i += 1;
}
byte[] n5 = new byte[]{29, 107, 73, 14, 123, 67};
buffer.write("退款码".getBytes("gbk"));
buffer.write(n1);buffer.write(n2);buffer.write(n5);buffer.write(n3);
outputStream.write(buffer.toByteArray());//写入

public boolean isIPv4Address(final String input) {
    Pattern IPV4_PATTERN = Pattern.compile("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][09-]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
    return IPV4_PATTERN.matcher(input).matches();
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值