esp-pos打印图片和二维码

来源:互联网 发布:网络悬疑剧两小无猜 编辑:程序博客网 时间:2024/05/01 23:48

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();}
0 0
原创粉丝点击