0

I am implementing POS bluetooth printer with ESC/POS commands and trying to print bitmap image. Image is getting printing but always it is printing some white space at start and then printing an image,because of which i am not able to print 1 image per label. following is my code for printing and image

    int bmpNewWidth = bmp.getWidth();
    int bmpNewHeight = bmp.getHeight();

    byte[] printBMPPackageHead = ESCUtil.bmpCmdHead(bmpMode,bmpNewWidth);

    int bmpBlockHeight = 0;
    int bmpBlockNums =0;
    if((bmpMode == 0) || (bmpMode ==1))
    {
        bmpBlockHeight = 8;
    }
    else if((bmpMode == 32) || (bmpMode ==33))
    {
        bmpBlockHeight = 24;
    }
    else
    {
        Log.d(TAG,"****bmpMode set error!!*****");
        return (new byte[1]);
    }
    bmpBlockNums = ((bmpNewHeight % bmpBlockHeight) == 0)? (bmpNewHeight/bmpBlockHeight) : (bmpNewHeight/bmpBlockHeight +1);
    int bmpBlockCMDSize = printBMPPackageHead.length + bmpNewWidth*bmpBlockHeight/8;
    byte[] bmpPrintData = new byte[bmpBlockNums*bmpBlockCMDSize];
    for(int n = 0; n < bmpBlockNums; n++)
    {
        byte[] bmpBlockPxBytes = getBitmapBlockData(n,bmpNewWidth,bmpBlockHeight,bmp);

        byte[][] bmpBlockPrintData = {printBMPPackageHead,bmpBlockPxBytes};
        System.arraycopy(ESCUtil.byteMerger(bmpBlockPrintData),0,bmpPrintData,n*bmpBlockCMDSize,bmpBlockCMDSize);
    }

  return bmpPrintData;
}

and

    public static byte[] bmpCmdHead(int mode, int bitmapWidth)
    {
    //byte[] result = new byte[]{ESC,42,0,0,0};
    byte[] result = new byte[]{ESC,42,0,0,0};
    result[2] = (byte)mode;
    result[3] = (byte)(bitmapWidth%256);
    result[4] = (byte)(bitmapWidth/256);
    return result;
}

   public static byte[] getBitmapBlockData(int blocknum, int bmpWidth, int bmpBlockHeight, Bitmap bmp)
{
    int blockHeightBytes = bmpBlockHeight/8;
    byte[] blockData = new byte[bmpWidth*blockHeightBytes];
    for (int i = 0;i < bmpWidth; i++)
    {
        for(int j = 0;j < blockHeightBytes;j++)
        {
            for(int p = 0; p < 8; p++)
            {
                byte px = px2Byte(i,blocknum * bmpBlockHeight+j*8+p,bmp);
                blockData[i*blockHeightBytes+j] |= (px << (7-p));
            }
        }
    }
    return  blockData;
}

this is it.Before calling this function i have called only init printer command that's it. Please help me. Thanks in advance.

sups
  • 113
  • 1
  • 16
  • There are many individual specifications for bluetooth printers and communication libraries. Adding the information about which vendor, what device, and what library will help you get the answer. – kunif May 09 '20 at 06:30
  • HI, i am having Milestone Printer, they don't have API or such,just a Sample project they have it on their site.Above given code is a part of it only – sups May 11 '20 at 12:54
  • Your question lacks enough information to help you get an answer. Please add information such as what I commented earlier, the ESCPOS command specifications supported by the printer, and what commands you actually send other than bitmap printing. – kunif May 11 '20 at 13:35
  • I am sending only initprinter command and above mention 1st function which in turns calling below mentioned "bmpCmdHead" and "getBitmapBlockData" these functions. Init printer command is having following code public static byte[] init_printer() { byte[] result = new byte[2]; result[0] = ESC; result[1] = 64; return result; } – sups May 15 '20 at 10:44
  • The content and layout that can be written in the comment are poor, so please edit the question article and add it. And the device information, command specifications, used library information, etc. are still lacking. – kunif May 15 '20 at 10:57

0 Answers0