我用热敏打印机的ESC * 命令打印图片时为什么打印后的是乱码。代码是从C#中修改的
Bitmap bt = BitmapFactory.decodeFile(MainActivity.path + message); if (bt !=null){
mService.write(ESC_INIT);
//mService.write(ESC_STANDARD);
byte[] data = new byte[] { 0x1B, 0x33, 0x00 };
mService.write(data);
//socket.Send(data, data.Length, 0);
data[0] = 0x00;
data[1] = 0x00;
data[2] = 0x00; // Clear to Zero.
// ESC * m nL nH 点阵图
byte[] escBmp = new byte[] { 0x1B, 0x2A, 0x00, 0x00, 0x00 };
int pixelColor;
escBmp[2] = 0x21;
//nL, nH
escBmp[3] = (byte)(bt.getWidth() % 256);
escBmp[4] = (byte)(bt.getWidth() / 256);
// data
for (int i = 0; i < (bt.getHeight() / 24 + 1); i++)
{
mService.write(escBmp);
for (int j = 0; j < bt.getWidth(); j++)
{
for (int k = 0; k < 24; k++)
{
if (((i * 24) + k) < bt.getHeight()) // if within the BMP size
{
pixelColor = bt.getPixel(j, (i * 24) + k);
if (pixelColor != -1)
{
data[k / 8] += (byte)(-128 >> (k % 8));
//data[k / 8] += 1;
}
}
}
mService.write(data);
data[0] = 0x00;
data[1] = 0x00;
data[2] = 0x00; // Clear to Zero.