此处代码:
private void print_image(String file) throws IOException {
File fl = new File(file);
OutputStream os = mBluetoothSocket
.getOutputStream();
if (fl.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(file);
convertBitmap(bmp);
os.write(PrinterCommands.SET_LINE_SPACING_24);
int offset = 0;
while (offset < bmp.getHeight()) {
os.write(PrinterCommands.SELECT_BIT_IMAGE_MODE);
for (int x = 0; x < bmp.getWidth(); ++x) {
for (int k = 0; k < 3; ++k) {
byte slice = 0;
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));
}
os.write(slice);
}
}
offset += 24;
os.write(PrinterCommands.FEED_LINE);
os.write(PrinterCommands.FEED_LINE);
os.write(PrinterCommands.FEED_LINE);
os.write(PrinterCommands.FEED_LINE);
os.write(PrinterCommands.FEED_LINE);
os.write(PrinterCommands.FEED_LINE);
}
os.write(PrinterCommands.SET_LINE_SPACING_30);
} else {
Toast.makeText(this, "file doesn't exists", Toast.LENGTH_SHORT)
.show();
}
}
AND PrinterCommands.class
public static final byte[] INIT = {27, 64}; public static byte[]
FEED_LINE = {10};
public static byte[] SELECT_FONT_A = {27, 33, 0};
public static byte[] SET_BAR_CODE_HEIGHT = {29, 104, 100}; public static
byte[] PRINT_BAR_CODE_1 = {29, 107, 2}; public static byte[]
SEND_NULL_BYTE = {0x00};
public static byte[] SELECT_PRINT_SHEET = {0x1B, 0x63, 0x30, 0x02};
public static byte[] FEED_PAPER_AND_CUT = {0x1D, 0x56, 66, 0x00};
public static byte[] SELECT_CYRILLIC_CHARACTER_CODE_TABLE = {0x1B, 0x74,
0x11};
public static byte[] SELECT_BIT_IMAGE_MODE = {0x1B, 0x2A, 33, (byte) 255,
3}; public static byte[] SET_LINE_SPACING_24 = {0x1B, 0x33, 24}; public
static byte[] SET_LINE_SPACING_30 = {0x1B, 0x33, 30};
帮我配置PrinterCommands为真