title: Printing Bitmap to raw socket 9100 Android
body: <p>I've managed to print normal txt to a printer so i know i can communicate with the printer but i cannot print and image, it prints funny characters.</p>
  
  <pre><code>public byte[] getBytesFromBitmap(Bitmap bitmap) {
  int bytes = bitmap.getByteCount();
  ByteBuffer buffer = ByteBuffer.allocate(bytes); 
  bitmap.copyPixelsToBuffer(buffer); 
  return buffer.array();
  </code></pre>
  
  <p>}</p>
  
  <pre><code>private void doPrintJob() throws UnknownHostException, IOException {
  Socket objSocket = new Socket("10.10.0.37", 9100);
  OutputStream  objOutputStream;
  objOutputStream = objSocket.getOutputStream();
  Bitmap image = BitmapFactory.decodeResource(getResources(),
              R.drawable.ic_launcher);
  objOutputStream.write(getBytesFromBitmap(image));
  
  objOutputStream.close();
  objSocket.close();
  </code></pre>
  
  <p>}</p>
  
  <p>Now i know a few of you may say i need to send a PCL or PS file - i dont know how &amp; how would i make my Bitmap into a PS/PCl file and how would i send it. </p>
  
  <p>Thanks</p>