title: How to print image with text from android phone to Bluetooth printer.?
body: <p>I want to print some text with image which is reside on my android phone to Bluetooth printer but text is successfully printed and image is not printed on paper.</p>
  
  <p>I using following code:</p>
  
  <pre><code>public class SendingdataActivity extends Activity {
  /** Called when the activity is first created. */
  private BluetoothAdapter mBluetoothAdapter = null;
  static final UUID MY_UUID =
  UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
  static String address = "50:C3:00:00:00:00";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  if (mBluetoothAdapter == null) {
  Toast.makeText(this,
  "Bluetooth is not available.",
  Toast.LENGTH_LONG).show();
  finish();
  return;
  }
  
  
  if (!mBluetoothAdapter.isEnabled()) {
  Toast.makeText(this,
  "Please enable your BT and re-run this program.",
  Toast.LENGTH_LONG).show();
  finish();
  return;
  }
  final SendData sendData = new SendData();
  Button sendButton = (Button) findViewById(R.id.send);
  sendButton.setOnClickListener(new OnClickListener() {
  public void onClick(View view) {
  sendData.sendMessage();
  }
  });
  }
  class SendData extends Thread {
  private BluetoothDevice device = null;
  private BluetoothSocket btSocket = null;
  private OutputStream outStream = null;
  
  public SendData(){
  device = mBluetoothAdapter.getRemoteDevice(address);
  try
  {
   btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
  }
  catch (Exception e) {
  // TODO: handle exception
  }
  mBluetoothAdapter.cancelDiscovery();
  try {
  btSocket.connect();
  } catch (IOException e) {
  try {
  btSocket.close();
  } catch (IOException e2) {
  }
  }
  Toast.makeText(getBaseContext(), "Connected to " + device.getName(),    
  Toast.LENGTH_SHORT).show();
  try {
  outStream = btSocket.getOutputStream();
  } catch (IOException e) {
  }
  }
  
  public void sendMessage()
  {
  try {
  mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.white);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  bm.compress(Bitmap.CompressFormat.JPEG, 100,baos); //bm is the bitmap object
  byte[] b = baos.toByteArray();
  Toast.makeText(getBaseContext(), String.valueOf(b.length), Toast.LENGTH_SHORT).show();
  outStream.write(b);
  outStream.flush();
  } catch (IOException e) {
  }
  }
  }
  }
  </code></pre>
  
  <p>This code works and print only text on paper.</p>
  
  <p>Thanks.</p>