2015-10-20 3 views
0

Я использую следующий код, чтобы напечатать растровое изображение с Android SDK, который можно найти по этой ссылке: https://www.zebra.com/us/en/products/software/barcode-printers/link-os/link-os-sdk.html#mainpartabscontainer_794f=downloadsZebra RW420 Android SDK напечатать несколько копий избегая петлю

//variables 
int printQty= 3; 
String printerAddress= ...; 

Connection connection = new BluetoothConnection(printerAddress); 
connection.open(); 

//for removing the useless margin printed 
connection.write("! U1 JOURNAL\r\n! U1 SETFF 100 2\r\n".getBytes()); 

ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection); 
Bitmap bitmapToPrint = large bitmap here; 
ZebraImageAndroid zebraImageToPrint = new ZebraImageAndroid(bitmapToPrint); 

for (int i = 0; i < printQty; i++){ 
    printer.printImage(zebraImageToPrint, 0, 0, -1, -1, false); 
} 

bitmapToPrint.recycle(); 
connection.close(); 

Проблема заключается в том : Процесс печати занимает много времени, потому что битмап большой.
Есть ли способ избежать цикла и рассказать принтеру, сколько количества для печати без звонка printImage несколько раз?

Я много искал в документации, но я не нашел что-то полезное, есть ли способ достичь этого? С CPCL я могу добиться такого же эффекта?

Благодаря Мат

ответ

0

Это, как я ее решил в конце

int printQty = 5; //or whatever number you want 
Coonection connection = new BluetoothConnection(deviceAddress); 
connection.open(); 
//with SETFF command we add 50 millimiters of margin at the end of the the print (without this the print is wasting a lot of paper) 
//ref https://km.zebra.com/kb/index?page=forums&topic=021407fb4efb3012e55595f77007e8a 
connection.write("! U1 JOURNAL\r\n! U1 SETFF 50 2\r\n".getBytes()); 
ZebraPrinter printer = ZebraPrinterFactory.getInstance(PrinterLanguage.CPCL, connection); 
//get the bitmap to print 
bitmapToPrint = PdfUtils.pdfToBitmap(getApplicationContext(), pdfStamped, 0); 

int width = bitmapToPrint.getWidth(); 
int height = bitmapToPrint.getHeight(); 
float aspectRatio = width/ZEBRA_RW420_WIDTH; //ZEBRA_RW420_WIDTH = 800f 
float multiplier = 1/aspectRatio; 
//scale the bitmap to fit the ZEBRA_RW_420_WIDTH print 
bitmapToPrint = Bitmap.createScaledBitmap(bitmapToPrint, (int)(width * multiplier), (int)(height * multiplier), false); 

//get the new bitmap and add 20 pixel more of margin 
int newBitmapHeight = bitmapToPrint.getHeight() + 20; 
//create the Zebra object with the new Bitmap 
ZebraImageAndroid zebraImageToPrint = new ZebraImageAndroid(bitmapToPrint); 
//the image is sent to the printer and stored in R: folder 
printer.storeImage("R:TEMP.PCX", zebraImageToPrint, -1, -1); 

//create the print commands string 
String printString = 
     "! 0 200 200 " + newBitmapHeight + " " + printQty + "\r\n"//set the height of the bitmap and the quantity to print 
     + "PW 831"           + "\r\n"//MAX_PRINT_WIDTH 
     + "TONE 50"           + "\r\n"//print intensity tone 0-200 
     + "SPEED 2"           + "\r\n"//print speed (less = more accurate) 1 2.5cm/s | 2 - 5cm/s | 3 - 7.6cm/s 
     + "ON-FEED REPRINT"         + "\r\n"//enable reprint on FEED button press 
     + "NO-PACE"           + "\r\n" 
     + "BAR-SENSE"          + "\r\n" 
     + "PCX 20 20 !<TEMP.PCX"       + "\r\n"//get the image we stored before in the printer 
     + "FORM"           + "\r\n" 
     + "PRINT"           + "\r\n";//print  
//send the commands to the printer, the image will be printed now 
connection.write(printString.getBytes()); 

//delete the image at the end to prevent printer memory sutaration 
connection.write("! U1 do \"file.delete\" \"R:TEMP.PCX\"\r\n".getBytes()); 
//close the connection with the printer 
connection.close(); 
//recycle the bitmap 
bitmapToPrint.recycle(); 
1

использование storeimage для хранения изображений на принтере. Затем отправьте команды pritner для печати изображения с типом печати из трех. Это ваш принтер использует zpl, он будет выглядеть примерно так: «^ xa^xgR: image.grf^fs^pq3^xz»

Вы обязательно захотите посмотреть руководство ZPL, но это общее решение. Сохраните изображение, а затем вспомните его. В конце удалите изображение или просто всегда используйте одно и то же имя файла, и изображение будет просто писать по последнему изображению.

+0

я постараюсь его в ближайшие дни, спасибо :) – MatPag

+0

Проблемы преобразующего JPEG в ГФП с Java кодом, потому что нет родной команды для печати сохраненных JPEG или PNG, я попробую что-то, что я нашел здесь: http://stackoverflow.com/questions/21905693/convert-image-to-grf-format – MatPag

+0

^XG должен работать с файлом .PNG – banno

Смежные вопросы