【问题标题】:Star micronics receipt printer image from database来自数据库的 Star micronics 收据打印机图像
【发布时间】:2016-09-23 18:50:23
【问题描述】:

我有一个 sm-t300i,我想弄清楚如何从数据库中打印图像。我有图像数据,但不知道如何插入。我已经成功地从资产中添加了图像,但不确定如何从原始图像数据中添加图像。下面的代码来自资产。同样由于某种原因,下面代码中的图像不会居中,我还需要做些什么来使图像居中。谢谢。

  AssetManager assetManager = mContext.getAssets();
    InputStream istr = null;
    try {
        istr = assetManager.open("www/img/logo.bmp");
    } catch (IOException e) {
        e.printStackTrace();
    }

    Bitmap bm = BitmapFactory.decodeStream(istr);

    StarBitmap starbitmap = new StarBitmap(bm, false, 200);


    commands.add(new byte[] { 0x1b, 0x61, 0x01 }); //align center

    commands.add(starbitmap.getImageEscPosDataForPrinting(false,false));

【问题讨论】:

    标签: java printing receipt


    【解决方案1】:

    看起来你可以只转换base64并使其成为位图

    String imagex = "iVBORw0KGgoAAAANS  etc";
    Bitmap bm = StringToBitMap(imagex);
    StarBitmap starbitmap = new StarBitmap(bm, true, 600);
    commands.add(starbitmap.getImageEscPosDataForPrinting(false,true));
    
    
    public Bitmap StringToBitMap(String encodedString){
        try {
            byte [] encodeByte=Base64.decode(encodedString, Base64.DEFAULT);
            Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
            return bitmap;
        } catch(Exception e) {
            e.getMessage();
            return null;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 2012-05-05
      • 2021-10-07
      • 2018-01-05
      相关资源
      最近更新 更多