JAVA ESC Pos将NV图形上载到打印机

JAVA ESC Pos将NV图形上载到打印机,java,android,bitmap,epson,escpos,Java,Android,Bitmap,Epson,Escpos,使用Esc/Pos,我想将位图图像上传到打印机上的NV图形内存中 我正在使用Esc/Pos手册中的GS(L/GS 8 L) 我可以使用和删除所有或一个图形 我知道在将位图添加到函数时遗漏了一些内容 这是我的命令字符串,包括位图。bitmapString删除了位图的文件头和信息头(前62个字节)(DataOffset): 但当我打印图形时,它会失真: 我已经解决了这个问题 发送的位图字节必须使用以下方法进行解码。该方法将位图像素转换为单色字节。1或0 希望这对将来有帮助 public static

使用Esc/Pos,我想将位图图像上传到打印机上的NV图形内存中

我正在使用Esc/Pos手册中的
GS(L/GS 8 L

我可以使用
删除所有或一个图形

我知道在将位图添加到函数时遗漏了一些内容

这是我的命令字符串,包括位图。
bitmapString
删除了位图的文件头和信息头(前62个字节)(DataOffset):

但当我打印图形时,它会失真:

我已经解决了这个问题

发送的位图字节必须使用以下方法进行解码。该方法将位图像素转换为单色字节。1或0

希望这对将来有帮助

public static byte[] decodeBitmap(byte[] bitmapBytes) {

    Bitmap bmp = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length);

    int zeroCount = bmp.getWidth() % 8;
    String zeroStr = "";
    if (zeroCount > 0) {
        for (int i = 0; i < (8 - zeroCount); i++) {
            zeroStr = zeroStr + "0";
        }
    }

    List<String> list = new ArrayList<>();
    for (int i = 0; i < bmp.getHeight(); i++) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < bmp.getWidth(); j++) {
            int color = bmp.getPixel(j, i);

            int r = (color >> 16) & 0xff;
            int g = (color >> 8) & 0xff;
            int b = color & 0xff;

            // if color close to white,bit='0', else bit='1'
            if (r > 160 && g > 160 && b > 160)
                sb.append("0");
            else
                sb.append("1");
        }
        if (zeroCount > 0) {
            sb.append(zeroStr);
        }

        list.add(sb.toString());
    }

    List<String> bmpHexList = binaryListToHexStringList(list);
    List<String> commandList = new ArrayList<>();
    commandList.addAll(bmpHexList);

    return hexListToBytes(commandList);
}
公共静态字节[]解码位图(字节[]位图字节){
位图bmp=BitmapFactory.decodeByteArray(bitmapBytes,0,bitmapBytes.length);
int zeroCount=bmp.getWidth()%8;
字符串zeroStr=“”;
如果(零计数>0){
对于(int i=0;i<(8-零计数);i++){
zeroStr=zeroStr+0;
}
}
列表=新的ArrayList();
对于(int i=0;i>16)&0xff;
int g=(颜色>>8)&0xff;
int b=颜色&0xff;
//如果颜色接近白色,则位='0',否则位='1'
如果(r>160&&g>160&&b>160)
某人附加(“0”);
其他的
某人附加(“1”);
}
如果(零计数>0){
sb.追加(zeroStr);
}
添加(sb.toString());
}
列表bmpHexList=binarylisttohextringlist(列表);
List commandList=new ArrayList();
commandList.addAll(bmpHexList);
返回hexListToBytes(commandList);
}
EpsonIo epsonio = new EpsonIo();
byte[] commandBytes = commandString.getBytes(Charsets.US_ASCII);

        epsonio.open(DevType.BLUETOOTH, MAC, null, ESCPosService.this);

        while (n > 0) {

            epsonio.write(commandBytes, i, n > bufferSize ? bufferSize : n, SEND_TIMEOUT);

            Thread.sleep(450);

            i += bufferSize;
            n -= bufferSize;
        }
public static byte[] decodeBitmap(byte[] bitmapBytes) {

    Bitmap bmp = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length);

    int zeroCount = bmp.getWidth() % 8;
    String zeroStr = "";
    if (zeroCount > 0) {
        for (int i = 0; i < (8 - zeroCount); i++) {
            zeroStr = zeroStr + "0";
        }
    }

    List<String> list = new ArrayList<>();
    for (int i = 0; i < bmp.getHeight(); i++) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < bmp.getWidth(); j++) {
            int color = bmp.getPixel(j, i);

            int r = (color >> 16) & 0xff;
            int g = (color >> 8) & 0xff;
            int b = color & 0xff;

            // if color close to white,bit='0', else bit='1'
            if (r > 160 && g > 160 && b > 160)
                sb.append("0");
            else
                sb.append("1");
        }
        if (zeroCount > 0) {
            sb.append(zeroStr);
        }

        list.add(sb.toString());
    }

    List<String> bmpHexList = binaryListToHexStringList(list);
    List<String> commandList = new ArrayList<>();
    commandList.addAll(bmpHexList);

    return hexListToBytes(commandList);
}