Java 如何通过蓝牙打印机打印图像

Java 如何通过蓝牙打印机打印图像,java,android,eclipse,printing,bluetooth,Java,Android,Eclipse,Printing,Bluetooth,有人知道如何在android中通过蓝牙打印机打印图像吗?。。。我正在使用下面的代码打印字符串,我无法更改字体样式,因此我想打印一张图像 以下是我打印字符串消息的方式: public void printNa(View v) { printFare = amount.getText().toString(); try { PRINTER_MAC_ID = "00:12:F3:19:4D:D8";

有人知道如何在android中通过蓝牙打印机打印图像吗?。。。我正在使用下面的代码打印字符串,我无法更改字体样式,因此我想打印一张图像

以下是我打印字符串消息的方式:

public void printNa(View v) {
        printFare = amount.getText().toString();
            try {
                PRINTER_MAC_ID = "00:12:F3:19:4D:D8";
                print_message = "This is the sample String";


                    mBTAdapter = BluetoothAdapter.getDefaultAdapter();
                    dialogProgress = new Dialog(Ticketing.this);
                    try {
                        if (mBTAdapter.isDiscovering()){
                            mBTAdapter.cancelDiscovery();
                        }else{
                            mBTAdapter.startDiscovery();
                        }
                } catch (Exception e) {
                    Toast.makeText(this, "Unable to print: " + e, Toast.LENGTH_LONG).show();
                    return;
                }
                    System.out.println("BT Searching status :" + mBTAdapter.isDiscovering());
                    if (mBTAdapter == null) {
                        Toast.makeText(this, "Device has no bluetooth capability",Toast.LENGTH_LONG).show();
                        return;
                    }else{
                        if (!mBTAdapter.isEnabled()) {
                            Intent i = new Intent( BluetoothAdapter.ACTION_REQUEST_ENABLE);
                            startActivityForResult(i, 0);
                        }
                        // Register the BroadcastReceiver
                        IntentFilter filter = new IntentFilter(
                        BluetoothDevice.ACTION_FOUND);
                        registerReceiver(mReceiver, filter);
                    }

                } catch (Exception e) {
                    Toast.makeText(this, "Unable to print: " + e, Toast.LENGTH_LONG).show();
                    return;
                }
        }   
    /********/
    public void printBillToDevice(final String address) {
        mBTAdapter.cancelDiscovery();
        try {           
            BluetoothDevice mdevice = mBTAdapter.getRemoteDevice(address);
            Method m = mdevice.getClass().getMethod("createRfcommSocket",new Class[] { int.class });
            mBTSocket = (BluetoothSocket) m.invoke(mdevice, 1);
            mBTSocket.connect();

            //  image = "logo";
            //  print_image(Environment.getExternalStorageDirectory().toString() + "/LOGO.png");
        //  byte[] format = { 27, 33, 0 };
        //  byte[] arrayOfByte1 = { 27, 33, 0 };

            int copyPrintIs = Integer.parseInt(copyPrint);
                for(int x = 1; x <= copyPrintIs; x++){
                    OutputStream os = mBTSocket.getOutputStream();
                    os.flush();
                    //os.write(iu_ini_ang_ipiprint.getBytes());
                    // Bold
            //format[2] = ((byte)(0x8 | arrayOfByte1[2]));
                    // Height
            //format[2] = ((byte)(0x10 | arrayOfByte1[2]));
                    // Width
                //format[2] = ((byte) (0x20 | arrayOfByte1[2]));
                    //out.write(str.getBytes(),0,str.getBytes().length);
        //os.write(format);
                    os.write(print_message.getBytes(),0,print_message.getBytes().length);
                    System.out.println(iu_ini_ang_ipiprint);
                    SystemClock.sleep(4000);
                }
            copyPrint = "1";
            if (mBTAdapter != null)
                mBTAdapter.cancelDiscovery();
                mBTSocket.close();
                setResult(RESULT_OK);
        }catch(Exception e) {
                Log.e("Class ", "My Exe ", e);
                e.printStackTrace();
                setResult(RESULT_CANCELED);
                return;
        }
}
    /********/
    /********/
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            try {
                String action = intent.getAction();
                // When discovery finds a device
                if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    // Get the BluetoothDevice object from the Intent
                    BluetoothDevice device = intent
                            .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    System.out.println("***" + device.getName() + " : "
                            + device.getAddress());

                    if (device.getAddress().equalsIgnoreCase(PRINTER_MAC_ID)) {
                        mBTAdapter.cancelDiscovery();
                        dialogProgress.dismiss();
                        Toast.makeText(Ticketing.this,device.getName() + " Printing reciept", Toast.LENGTH_LONG).show();
                            printBillToDevice(PRINTER_MAC_ID);
                    }
                }
            } catch (Exception e) {
                Toast.makeText(Ticketing.this,"Error printing reciept: " + e,Toast.LENGTH_LONG).show();
                return;
            }
        }
    };
我无法找到一个好的解决方案来改变我的字体风格,所以我决定打印一个图像文件,但我无法找到一个好的解决方案来再次通过热敏打印机打印图像,我使用的是APEX 3打印机。 我是新来的,所以任何帮助都将被感激

对不起,我的英语不好


谢谢大家!

尝试此链接:我以前已经找到此链接,但我无法解决我的问题…此链接无法解决我的问题。。你现在解决问题了吗?。。。Bernzkie您的图像是黑白格式的吗?