android usb打印机使用esc / pos

时间:2015-08-03 03:14:33

标签: android printing

我尝试通过USB打印图像post 但它只打印非字符,我的打印机是兄弟HL-5340D。

SELECT_BIT_IMAGE_MODE命令

public final static byte[] SELECT_BIT_IMAGE_MODE = {0x1B, 0x2A, 33, 255,3};

这是我的打印方法

private void printImage(Bitmap bmp) {
    convertBitmap(bmp);
    connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.INIT_PRINTER, PrinterCommands.INIT_PRINTER.length, 100000);
    connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.SET_LINE_SPACE_24, PrinterCommands.SET_LINE_SPACE_24.length, 100000);

    int offset = 0;
    while (offset < bmp.getHeight()) {
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.SELECT_BIT_IMAGE_MODE, PrinterCommands.SELECT_BIT_IMAGE_MODE.length, 100000);

        for (int x = 0; x < bmp.getWidth(); ++x) {
            byte slice = 0;
            byte[] imageDataLine = new byte[bmp.getWidth()];

            for (int k = 0; k < 3; ++k) {


                for (int b = 0; b < 8; ++b) {
                    int y = (((offset / 8) + k) * 8) + b;
                    int i = (y * bmp.getWidth()) + x;
                    boolean v = false;
                    if (i < dots.length()) {
                        v = dots.get(i);
                    }
                    slice |= (byte) ((v ? 1 : 0) << (7 - b));
                    imageDataLine[x] = slice;
                }
            }
            connection.bulkTransfer(mEndpointBulkOut, imageDataLine, imageDataLine.length, 100000);
        }
        offset += 24;
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.LINE_FEED, PrinterCommands.LINE_FEED.length, 100000);
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.LINE_FEED, PrinterCommands.LINE_FEED.length, 100000);
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.LINE_FEED, PrinterCommands.LINE_FEED.length, 100000);
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.LINE_FEED, PrinterCommands.LINE_FEED.length, 100000);
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.LINE_FEED, PrinterCommands.LINE_FEED.length, 100000);
        connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.LINE_FEED, PrinterCommands.LINE_FEED.length, 100000);

    }
    connection.bulkTransfer(mEndpointBulkOut, PrinterCommands.SET_LINE_SPACE_30, PrinterCommands.SET_LINE_SPACE_30.length, 100000);


}

我做错了吗?

0 个答案:

没有答案