标志形象没有得到中心的收据打印机对齐

问题描述 投票:2回答:1

打印机不带图像的比对中帐户。标志总是留给默认对齐。 Text获取没有问题对齐。因此,有什么不对。当我设置了while循环中的对齐aligncenter()方法中,一连串的问号获得所有打印在纸上。

public void printImage(Bitmap bitmap, boolean center) {

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int newWidth = this.mType58 ? 384 : 576;

       if (width > (this.mType58 ? 384 : 576)) {
            bitmap = LibUtil.setImgSize(bitmap, (float) newWidth, (float) (height / (width / newWidth)), (float) width, (float) height);
       }

    try {
          PrinterWriter mThirdPrinter = this.mType58 ? new PrinterWriter58mm(384, 384) : new PrinterWriter80mm(576, 576);            
          ArrayList<byte[]> datas = mThirdPrinter.getImageByte(bitmap);

           if (mThirdPrinter.getDataAndClose() == null) {

               if (this.mCallback != null) {
                     this.mCallback.onError(ErrorCode.IMAGE_NOT_FONUD);
           }

          return;
      }

        try {
               datas.add(mThirdPrinter.getDataAndClose());
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

        if (datas == null) {
            DebugLog.LogD("imgpath is empty, datas is null, maybe is TFCard");
            return;
        }

        this.mPrinterModule.sendData(new byte[]{(byte) 27, (byte) 74, (byte) 0});

        Iterator it = datas.iterator();
        byte [] alignment = alignCenter();          
        int i = 0 ;
        byte [] data1 = null ;

        while (it.hasNext()) {              
            data1[i] = (byte) it.next();
        }

        this.mPrinterModule.sendData(alignment);
        this.mPrinterModule.sendData(data1);

    } catch (IOException e2) {
        e2.printStackTrace();
    }

}
android thermal-printer escpos
1个回答
0
投票

当我在另一间办公室,而这种项目我有一个类似的问题,在库中的所有对齐特征没有工作。但我有棘手的解决方案,使标志图像获取中心。我画一个位图用白色或透明的分辨率,并放置正好在接到中间的宽度的位置

public Bitmap createBitmap(Rect rectImage, int i, int j) {

        Paint p = new Paint();
        p.setStyle(Style.FILL_AND_STROKE);
        p.setAntiAlias(true);
        p.setFilterBitmap(true);
        p.setDither(true);
        p.setColor(Color.WHITE);

        Bitmap bitmap = Bitmap.createBitmap(rectImage.width() * 2,
                rectImage.height() * 2, Bitmap.Config.ARGB_8888);

        Canvas c = new Canvas(bitmap);
//      c.drawColor(Color.RED);
        c.drawRect(rectImage.left, rectImage.top, rectImage.right,
                rectImage.bottom, p);
        return bitmap;

    }

然后用您的徽标合并此位图,请使用类似下面的代码(不是这个代码)

public static Bitmap mergeToPin(Bitmap left, Bitmap right) {
    Bitmap result = Bitmap.createBitmap(left.getWidth(), left.getHeight(), left.getConfig());
    Canvas canvas = new Canvas(result);
    int widthleft = left.getWidth();
    int widthright = right.getWidth();
    canvas.drawBitmap(left, 0f, 0f, null);
    canvas.drawBitmap(right, widthleft, 0f, null);
    return result;
}

如你所知,在收到的大小可以预测的。这样就可以使静态值透明图像的宽度大小

© www.soinside.com 2019 - 2024. All rights reserved.