Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 标志图像不';不要在收据打印机中对齐中心_Android_Thermal Printer_Escpos - Fatal编程技术网

Android 标志图像不';不要在收据打印机中对齐中心

Android 标志图像不';不要在收据打印机中对齐中心,android,thermal-printer,escpos,Android,Thermal Printer,Escpos,打印机不考虑图像的对齐方式。默认情况下,徽标始终左对齐。文本对齐没有问题。因此,aligncenter()方法没有什么问题。当我在while循环中设置对齐方式时,一系列问号会打印在纸上 public void printImage(Bitmap bitmap, boolean center) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int newWidth = this.mTyp

打印机不考虑图像的对齐方式。默认情况下,徽标始终左对齐。文本对齐没有问题。因此,
aligncenter()
方法没有什么问题。当我在while循环中设置对齐方式时,一系列问号会打印在纸上

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();
    }

}
public void打印图像(位图,布尔中心){
int width=bitmap.getWidth();
int height=bitmap.getHeight();
int newWidth=this.mType58?384:576;
如果(宽度>(this.mType58-384:576)){
位图=LibUtil.setImgSize(位图,(浮点)新宽度,(浮点)(高度/(宽度/新宽度)),(浮点)宽度,(浮点)高度);
}
试一试{
PrinterWriter mThirdPrinter=this.mType58?新的PrinterWriter58mm(384384):新的PrinterWriter80mm(576576);
ArrayList data=mThirdPrinter.getImageByte(位图);
if(mThirdPrinter.getDataAndClose()==null){
如果(this.mCallback!=null){
this.mCallback.onError(ErrorCode.IMAGE\u NOT\u FONUD);
}
返回;
}
试一试{
add(mthirdprent.getDataAndClose());
}捕获(NullPointerException e){
e、 printStackTrace();
}
如果(数据==null){
LogD(“imgpath为空,数据为空,可能为TFCard”);
返回;
}
sendData(新字节[]{(字节)27,(字节)74,(字节)0});
迭代器it=datas.Iterator();
字节[]对齐=对齐中心();
int i=0;
字节[]数据1=null;
而(it.hasNext()){
data1[i]=(字节)it.next();
}
此.mPrinterModule.sendData(对齐);
这个.mPrinterModule.sendData(data1);
}捕获(IOE2异常){
e2.printStackTrace();
}
}

当我在另一个办公室时,这种项目我遇到了类似的问题,库中的所有对齐功能都不起作用。但我有一个棘手的解决方案,使标志图像得到中心。 <强>我用白色或透明的分辨率绘制位图并将宽度的位置正好放在收据的中间<强> < /p>
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;
}