Java ESC/POS-如何使用辅助字体打印图像?

Java ESC/POS-如何使用辅助字体打印图像?,java,escpos,Java,Escpos,我使用此示例打印图像(具有正确的8位移位): 当我将字体设置为9x17而不是12x24时,图像将以条纹打印: 左侧图像使用默认字体(12x24),右侧图像使用较小/压缩字体 我使用页面模式在左侧打印图像,在右侧打印文本。似乎我不能为每一面设置一种字体,所以我需要压缩字体 我把它设定为: private static final byte[] CONDENSED_ON = {ESC, 0x4D, 0x01}; 有没有关于我如何去掉条纹的提示 尝试将线高度设置为17,但未成功 完整代码: pu

我使用此示例打印图像(具有正确的8位移位):

当我将字体设置为9x17而不是12x24时,图像将以条纹打印:

左侧图像使用默认字体(12x24),右侧图像使用较小/压缩字体

我使用页面模式在左侧打印图像,在右侧打印文本。似乎我不能为每一面设置一种字体,所以我需要压缩字体

我把它设定为:

private static final byte[] CONDENSED_ON = {ESC, 0x4D, 0x01};
有没有关于我如何去掉条纹的提示

尝试将线高度设置为17,但未成功

完整代码:

public EscPosPrinter imprimeImagem(BufferedImage image) throws IOException {
    BitSet imageBits = getBitsImageData(image);

    int lsb = (image.getWidth() & 0xFF);
    int msb = ((image.getWidth() >> 8) & 0xFF);

    setLineSize(24);

    byte[] modoImagem = {ESC, 0x2A, (byte) 33, (byte) lsb, (byte) msb}; //33 = 24 pontos densidade dupla

    int offset = 0;
    while(offset < image.getHeight()) {
        envia(modoImagem);

        int imageDataLineIndex = 0;
        byte[] imageDataLine = new byte[3 * image.getWidth()];

        for(int x = 0; x < image.getWidth(); ++x) {
            // Remember, 24 dots = 24 bits = 3 bytes.
            // The 'k' variable keeps track of which of those
            // three bytes that we're currently scribbling into.
            for(int k = 0; k < 3; ++k) {
                byte slice = 0;

                // A byte is 8 bits. The 'b' variable keeps track
                // of which bit in the byte we're recording.
                for(int b = 0; b < 8; ++b) {
                    // Calculate the y position that we're currently
                    // trying to draw. We take our offset, divide it
                    // by 8 so we're talking about the y offset in
                    // terms of bytes, add our current 'k' byte
                    // offset to that, multiple by 8 to get it in terms
                    // of bits again, and add our bit offset to it.
                    int y = (((offset / 8) + k) * 8) + b;

                    // Calculate the location of the pixel we want in the bit array.
                    // It'll be at (y * width) + x.
                    int i = (y * image.getWidth()) + x;

                    // If the image (or this stripe of the image)
                    // is shorter than 24 dots, pad with zero.
                    boolean v = false;
                    if(i < imageBits.length()) {
                        v = imageBits.get(i);
                    }
                    // Finally, store our bit in the byte that we're currently
                    // scribbling to. Our current 'b' is actually the exact
                    // opposite of where we want it to be in the byte, so
                    // subtract it from 7, shift our bit into place in a temp
                    // byte, and OR it with the target byte to get it into there.
                    slice |= (byte) ((v ? 1 : 0) << (7 - b));
                }
                imageDataLine[imageDataLineIndex + k] = slice;
            }
            imageDataLineIndex += 3;
        }

        offset += 24;

        send(imageDataLine);
        send(LF);
    }
    resetLineSize();

    return this;
}
公共EscPosPrinter imprimeImagem(BuffereImage图像)引发IOException{
BitSet imageBits=getBitsImageData(图像);
int lsb=(image.getWidth()&0xFF);
int msb=((image.getWidth()>>8)和0xFF);
setLineSize(24);
byte[]modoImagem={ESC,0x2A,(byte)33,(byte)lsb,(byte)msb};//33=24 pontos densitidade dupla
整数偏移=0;
而(偏移量