how to print png image on imz220 (android)

Hi there

 

I'm hoping someone can point me in the right direction, currently Im able to send text to the printer without any issues but i would like to print an png asset as well but all i get is a string output. i am following this stackoverflow post - http://stackoverflow.com/questions/26100430/print-image-via-bluetooth-printer-prints-string/29383314#29383314 as i cant seem to find any offical documentation on how to do this correctly.

 

here is my test code:

 

package com.example.gareth.myzebraprinter;

 

import android.content.res.AssetManager;

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.drawable.BitmapDrawable;

import android.graphics.drawable.Drawable;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

 

import com.zebra.sdk.comm.BluetoothConnection;

import com.zebra.sdk.comm.Connection;

import com.zebra.sdk.comm.ConnectionException;

import com.zebra.sdk.graphics.ZebraImageFactory;

import com.zebra.sdk.graphics.ZebraImageI;

import com.zebra.sdk.printer.PrinterLanguage;

import com.zebra.sdk.printer.ZebraPrinter;

import com.zebra.sdk.printer.ZebraPrinterFactory;

import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;

import com.zebra.sdk.util.internal.Base64;

 

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.InputStream;

 

public class MainActivity extends AppCompatActivity {

 

   private ZebraPrinter zebraPrinter;

   private Connection connection;

 

   @Override
   protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

 

  connect();

  printTest();

  }

 

   private void printTest(){

 

   if(zebraPrinter != null){

 

   try {

  InputStream inputStream = getAssets().open("ic_launcher.png");

  ZebraImageI zebraImageI = ZebraImageFactory.getImage(BitmapFactory.decodeStream(inputStream));

   zebraPrinter.printImage(zebraImageI,250,0,0,-1,false);

  } catch (IOException e) {

  e.printStackTrace();

  } catch (ConnectionException e) {

  e.printStackTrace();

  }

 

// byte[] rcpt = "------------\n\r test test test".getBytes();
// try {
// connection.write(rcpt);
// } catch (ConnectionException e) {
// Log.e("printTest",e.getMessage());
// }
   }

  }

 

   private void connect(){

 

 

   connection = new BluetoothConnection("AC3FA41EF22E");

 

   try
   {

   connection.open();

  }

   catch (ConnectionException ex)

  {

  Log.e("connect","ConnectionException " + ex.getMessage());

  mSleeper.sleep(1000);

  closeConnection();

  }

   catch(Exception ex)

  {

  Log.e("connect","Exception "+ex.getMessage());

  }

 

   try
   {

   zebraPrinter = ZebraPrinterFactory.getInstance(connection);

  PrinterLanguage pl = zebraPrinter.getPrinterControlLanguage();

  Log.i("PrinterPanguage",pl.toString());

  }

   catch (ConnectionException ex)

  {

  Log.e("connect","ConnectionException " + ex.getMessage());

   zebraPrinter = null;

  mSleeper.sleep(1000);

  closeConnection();

  } catch(Exception ex)

  {

  Log.e("connect","Exception " + ex.getMessage());

   zebraPrinter = null;

  mSleeper.sleep(1000);

  closeConnection();

  }

  }

 

   private void closeConnection(){

 

   if(connection != null){

   try
   {

   connection.close();

  }

   catch (ConnectionException exx)

  {

  Log.e("closeConnection", exx.getMessage());

  }

  }

  }

}

Anonymous (not verified)
Hi Gareth,Sorry for the

Hi Gareth,

Sorry for the delayed response. We had some bug in our system and all the posts were hidden.

You can have a look at our ImagePrintDemo app for your reference on how to print graphics. Please find the below link and let me know if you have any questions. Hope it helps.

https://km.zebra.com/kb/index?page=content&id=SA172

Thank you,

Mounika Jasti.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Deivis Vargas
Buenas noche, estoy

Buenas noche, estoy realizando pruebas con el código de ustedes y no logro imprimir la imagen. Espero mas de su ayuda.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Joe Wallace
I can't find many samples,

I can't find many samples, source code is not complete or even not working in some cases, there are many broken links on the posts and there are pages with almost nothing of help for the developer. Please fix that.

Pd.: GitHub - Zebra/LinkOS-Android-Samples has only a user license agreement and zero android samples, it is too bad.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Joe, Sorry if this is

Hi Joe, Sorry if this is confusing, but the samples are branched from the 'empty' EULA project:

Where else have you been looking at broken sample code?  We are going through everything and trying to fix it as we transition to GitHub, so if you've found some, please let us know!  Also if there are samples you would like and we're not providing, let us know that as well.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments