Zebra Android Printing with v2.8.2148 images print as string instead of pixels -


in our android app, can print images p4t printer. use pcx cpcl command print image inline other receipt text. prior printing receipt upload image printer memory using zebra sdk. have zebra first convert our bitmap zebraimage , upload it. on p4t results in .pcx file reference in our cpcl label. example:

printer config:

e:signature.pcx 

in android app:

static private void sendimagestoprinter(deviceprinter deviceprinter, list<string> imagestosend, string rootpath) throws ioexception, connectionexception, zebraprinterlanguageunknownexception, zebraillegalargumentexception {     for(string image:imagestosend) {         //[0] -> image path, <[1]> -> image scale factor         string[] imageparams = image.split("\\|");         double scalefactor = imageparams.length > 1 ? parseimagescale(imageparams[1]) : 1.0d;          file file = new file(stringutils.pathcombine(rootpath,imageparams[0]));         if(!file.exists())             throw new filenotfoundexception("image file not found " + file.getname());          zebraimagei zebraimage = zebraimagefactory.getimage(bitmapfactory.decodefile(file.getabsolutepath()));          deviceprinter.storeimage("e:" + file.getname(), zebraimage, (int)(zebraimage.getwidth() * scalefactor), (int)(zebraimage.getheight() * scalefactor));     } }  public void storeimage(string printerfullpath, zebraimagei zebraimage, int width, int height) throws connectionexception, zebraprinterlanguageunknownexception, ioexception, zebraillegalargumentexception {     connection connection = null;     try {         connection = connectionbuilder.build(connectionstring);         connection.open();         zebraprinter printer = zebraprinterfactory.getinstance(connection);          printer.storeimage(printerfullpath, zebraimage, width, height);      }     {         if(connection != null)             connection.close();     } } 

the cpcl format file:

pcx 10 280 !<signature.pcx 

we set scaling parameter manage printer-stored image size. prints image fine on p4t printer have qln420 prints long character string representation of image.

the other text parts of receipt print on these devices.

anyone experience problem , know how fix it?

*edit i've tried directly printing zebra image printer using following code. no matter which, string (base64 representation of image.)

public void printimage(zebraimagei zebraimage, int width, int height) throws connectionexception, zebraprinterlanguageunknownexception, zebraillegalargumentexception {     connection connection = null;     try {         connection = connectionbuilder.build(connectionstring);         connection.open();         zebraprinter printer = zebraprinterfactory.getinstance(connection);         printer.printimage(zebraimage, 0, 0, width, height, false);     }     {         if(connection != null)             connection.close();     } } 

**edit on qln420 image never stored. i'm expecting show @ "e:sigfile.pcx" after calling storeimage() never saves. don't know why yet.

the fix explicitly set printer language when creating new printer storing image:

public void storeimage(string printerfullpath, zebraimagei zebraimage, int width, int height, printerlanguage printerlanguage) throws connectionexception, zebraprinterlanguageunknownexception, ioexception, zebraillegalargumentexception {     connection connection = null;     try {         connection = connectionbuilder.build(connectionstring);         connection.open();          zebraprinter printer = zebraprinterfactory.getinstance(printerlanguage, connection);          printer.storeimage(printerfullpath, zebraimage, width, height);      }     {         if(connection != null)             connection.close();     } } 

also, found removing image's file extension helpful 1 device remove file extension in cases now. us, printing cpcl format receipt inline image works on p4t, qln420 , zq520.

additionally, found scaling image prior storing necessary since large image store fail without throwing exception.

    zebraimagei zebraimage = zebraimagefactory.getimage(bitmapfactory.decodefile(file.getabsolutepath()));     double scalefactor = (printedimagewidth == null) ? 1.0 : (double)printedimagewidth / zebraimage.getwidth();     //strip off extension     string filename = file.getname().split("\\.")[0];     deviceprinter.storeimage(filename, zebraimage, (int)(zebraimage.getwidth() * scalefactor), (int)(zebraimage.getheight() * scalefactor), printerlanguage); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -