Impressão Imagem EPL

Alguém consegue ajudar sobre qual é forma correta de extrair bytes?
Tenho isso, mas não imprime o desenho corretamente.

sb = new StringBuilder();
    sb.append("N" + "\n");
    sb.append("I8,A,003" + "\n");
    sb.append("D12" + "\n");
    sb.append("S1" + "\n");
    sb.append("ZT" + "\n");
    sb.append("Q456,24");
    // Gera String byte da inagem
    sb.append("nGW15,15,".concat(p3 + "").concat(",").concat(bi.getHeight() + "").concat(","));
    for (int y = 0; y < bi.getHeight(); ++y) {
        // from left to right
        for (int x = 0; x < width;) {
            byte abyte = 0;
            // get 8 bits together and write to memory

            for (int b = 0; b < 8; ++b, ++x) {
                // set 1 for white,0 for black
                int dot = 1;

                // pixel still in width of bitmap,
                // check luminance for white or black, out of bitmap set to white
                if (x < bi.getWidth()) {
                    int c = bi.getRGB(x, y);
                    int red = (c & 0x00ff0000) >> 16;
                    int green = (c & 0x0000ff00) >> 8;
                    int blue = c & 0x000000ff;
                    Color color = new Color(red, green, blue);
                    int luminance = (int) ((color.getRed() * 0.3) + (color.getGreen() * 0.59)
                            + (color.getBlue() * 0.11));
                    dot = luminance > 127 ? 1 : 0;

                }

                abyte |= (byte) (dot << (7 - b)); // shift left,
                // then OR together to get 8 bits into a byte
            }

            sb.append(abyte);
        }
    }
    sb.append("\nP1\n");