2016-05-25 1 views
0

私は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)); 

答えて

0

あなただけの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; 
    } 
} 
作ることができるように見えます