11

Androidセルを介してBluetoothプリンターにテキストを送信しています。プリンターとデバイスの両方が Bluetooth 経由で接続されています。 それは正常に機能しており、紙に目的のテキストを取得しています。

私の質問は:

プリンターはデフォルトfont sizeのテキストを使用しています。印刷する文字のフォントサイズを変更したい。

どうすればこれを達成できますか??

ブルートゥース接続の後にテキストを印刷する私のコードは次のとおりです。

private void connect_print(BluetoothDevice bluetoothDevicess)  {
    // some code
    printData();
    // some code
}

printData() メソッド

private void printData() {
    // TODO Auto-generated method stub
    String str = new String("This is the text sending to the printer");
    String newline = "\n";
    try {
        out.write(str.getBytes(),0,str.getBytes().length);
        Log.i("Log", "One line printed");
    } catch (IOException e) {
        Toast.makeText(BluetoothDemo.this, "catch 1", Toast.LENGTH_LONG).show();
        e.printStackTrace();
        Log.i("Log", "unable to write ");
        flagCheck = false;
    }
    try {
        out.write(newline.getBytes(),0,newline.getBytes().length);
    } catch (IOException e) {        
        Log.i("Log", "Unable to write the new line::");
        e.printStackTrace();
        flagCheck = false;
    }
    flagCheck = true;
}

font sizeプリンターに送信しているテキストのとを変更しfont styleて印刷したい。これを達成するのを手伝ってください。誰かがリンクを提案できるなら、私も彼/彼女に感謝します. この問題の解決策を見つけるのを手伝ってください

4

2 に答える 2

8

こんにちは、同じテーマの私の答えにこれを書いてください:

こちらのスレッドですでに同じ質問をしましたが、まだ回答がありません。答えは1つしかありませんでしたが、役に立ちませんでした。

それがあなたを助けるかどうか見てみましょう. ここ

あなたがそれをやったら、私のスレッドで私に答えてください。私は間違いなくあなたに感謝します。

今、私はそれを行う方法を知っています.Linuxでdex2jarを使用し、次にJava逆コンパイラでjarを開きます...これを試してください...このコマンドを書くとき:

out.write(str.getBytes(),0,str.getBytes().length);

U は byte[] 配列をメソッドに送信しています。実際の byte[] 配列を送信する前に、別の byte[] 配列を送信してフォーマットを変更できます...

デフォルトのフォーマット byte[] 配列は次のとおりです。

byte[] arrayOfByte1 = { 27, 33, 0 };

だからあなたはこれを試すことができます:

byte[] format = { 27, 33, 0 };

out.write(format);

out.write(str.getBytes(),0,str.getBytes().length);

これらの行は、デフォルトのフォーマットテキストを出力しますが、そうします:

 byte[] format = { 27, 33, 0 };

format[2] = ((byte)(0x8 | arrayOfByte1[2]));

out.write(format);

out.write(str.getBytes(),0,str.getBytes().length);

テキストを太字で印刷します... Uはこの他の形式の配列を試すことができます:

            // Bold
            format[2] = ((byte)(0x8 | arrayOfByte1[2]));

            // Height
            format[2] = ((byte)(0x10 | arrayOfByte1[2]));

            // Width
            format[2] = ((byte) (0x20 | arrayOfByte1[2]));

            // Underline
            format[2] = ((byte)(0x80 | arrayOfByte1[2]));

            // Small
            format[2] = ((byte)(0x1 | arrayOfByte1[2]));

それを組み合わせることができますが、小さくて太字のテキストが好きな場合は、これらの配列割り当てのコメントを外してください。次に例を示します。

 byte[] format = { 27, 33, 0 };

    // Bold
format[2] = ((byte)(0x8 | arrayOfByte1[2]));
// Height
format[2] = ((byte)(0x10 | arrayOfByte1[2]));
// Width
format[2] = ((byte) (0x20 | arrayOfByte1[2]));
// Underline
// format[2] = ((byte)(0x80 | arrayOfByte1[2]));
// Small
// format[2] = ((byte)(0x1 | arrayOfByte1[2]));
    out.write(format);
    out.write(str.getBytes(),0,str.getBytes().length);

この最後のコードは、最大のテキストサイズを出力します...これがあなたに役立つことを願っています...

Pdta: 私の英語でごめんなさい

Pdta2:画像を印刷しようとしています。

于 2013-01-18T19:44:57.100 に答える
0

spanよくわかりませんが、Javaメソッドを使用してフォント スタイルを設定することで、これを実現できる可能性があります。

次のようなことを試してください:

int start=editbox.getSelectionStart();

int end=editbox.getSelectionEnd();

Spannable span=(Spannable)editbox.getText();

StyleSpan f = new StyleSpan( 
                        Typeface.createFromAsset(getAssets(),
                         "fonts/genbkbasr.ttf"));

span.setSpan(f, start,end, 0);

同様に、フォント スタイル、フォントの色などを適用できます。

詳細については、次を確認してください。

Android 開発: EditText の一部を Spannable に置き換える方法

アンドロイドで正規表現で SpannableString を使用するには?

于 2012-09-04T07:51:43.303 に答える