How to print the image At full paper size (80 mm) in the thermal printer (EPSON)

I followed the Epson SDK for android for thermal prints ...

So, instead of text, I am given some image that contains entire images. in the Logoimage section (store). As below

enter image description here

Here, the Shop is the logo that I set for my recipe (image). So, I get as described above. It does not print full size ...

this is my code

public class MainActivity extends Activity implements View.OnClickListener, ReceiveListener { private Context mContext = null; private EditText mEditTarget = null; private Spinner mSpnSeries = null; private Spinner mSpnLang = null; private Printer mPrinter = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = this; int[] target = { R.id.btnDiscovery, R.id.btnSampleReceipt, }; for (int i = 0; i < target.length; i++) { Button button = (Button)findViewById(target[i]); button.setOnClickListener(this); } mSpnSeries = (Spinner)findViewById(R.id.spnModel); ArrayAdapter<SpnModelsItem> seriesAdapter = new ArrayAdapter<SpnModelsItem>(this, android.R.layout.simple_spinner_item); seriesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); seriesAdapter.add(new SpnModelsItem(getString(R.string.printerseries_t20), Printer.TM_T20)); mSpnSeries.setAdapter(seriesAdapter); mSpnSeries.setSelection(0); try { Log.setLogSettings(mContext, Log.PERIOD_TEMPORARY, Log.OUTPUT_STORAGE, null, 0, 1, Log.LOGLEVEL_LOW); } catch (Exception e) { ShowMsg.showException(e, "setLogSettings", mContext); } mEditTarget = (EditText)findViewById(R.id.edtTarget); } @Override protected void onActivityResult(int requestCode, final int resultCode, final Intent data) { if (data != null && resultCode == RESULT_OK) { String target = data.getStringExtra(getString(R.string.title_target)); if (target != null) { EditText mEdtTarget = (EditText)findViewById(R.id.edtTarget); mEdtTarget.setText(target); } } } @Override public void onClick(View v) { Intent intent = null; switch (v.getId()) { case R.id.btnDiscovery: intent = new Intent(this, DiscoveryActivity.class); startActivityForResult(intent, 0); break; case R.id.btnSampleReceipt: updateButtonState(false); if (!runPrintReceiptSequence()) { updateButtonState(true); } break; case R.id.btnSampleCoupon: updateButtonState(false); if (!runPrintCouponSequence()) { updateButtonState(true); } break; default: // Do nothing break; } } private boolean runPrintReceiptSequence() { if (!initializeObject()) { return false; } if (!createReceiptData()) { finalizeObject(); return false; } if (!printData()) { finalizeObject(); return false; } return true; } private boolean createReceiptData() { String method = ""; Bitmap logoData = BitmapFactory.decodeResource(getResources(), R.drawable.store); StringBuilder textData = new StringBuilder(); final int barcodeWidth = 2; final int barcodeHeight = 100; if (mPrinter == null) { return false; } try { method = "addTextAlign"; mPrinter.addTextAlign(Printer.ALIGN_CENTER); method = "addImage"; mPrinter.addImage(logoData, 0, 0, logoData.getWidth(), logoData.getHeight(), Printer.COLOR_1, Printer.MODE_MONO, Printer.HALFTONE_DITHER, Printer.PARAM_DEFAULT, Printer.COMPRESS_AUTO); method = "addFeedLine"; mPrinter.addFeedLine(1); textData.append("EPSON PRINT DEMO TEST - (HYD)\n"); textData.append("STORE DIRECTOR – MLN\n"); textData.append("\n"); textData.append("07/06/12 09:15 012 0191 134\n"); textData.append("ST# 21 OP# 001 TE# 01 TR# 747\n"); textData.append("------------------------------\n"); method = "addText"; mPrinter.addText(textData.toString()); textData.delete(0, textData.length()); textData.append("524 3 CUP BLK TEAPOT 9.99 R\n"); textData.append("003 WESTGATE BLACK 25 59.99 R\n"); textData.append("------------------------------\n"); method = "addText"; mPrinter.addText(textData.toString()); textData.delete(0, textData.length()); textData.append("SUBTOTAL 69.98\n"); textData.append("TAX 14.43\n"); method = "addText"; mPrinter.addText(textData.toString()); textData.delete(0, textData.length()); method = "addTextSize"; mPrinter.addTextSize(2, 2); method = "addText"; mPrinter.addText("TOTAL 84.41\n"); method = "addTextSize"; mPrinter.addTextSize(1, 1); method = "addFeedLine"; mPrinter.addFeedLine(1); textData.append("CASH 200.00\n"); textData.append("CHANGE 78.14\n"); textData.append("------------------------------\n"); method = "addText"; mPrinter.addText(textData.toString()); textData.delete(0, textData.length()); textData.append("Purchased item total number\n"); textData.append("Sign Up and Save !\n"); textData.append("With Preferred Saving Card\n"); method = "addText"; mPrinter.addText(textData.toString()); textData.delete(0, textData.length()); method = "addFeedLine"; mPrinter.addFeedLine(2); method = "addCut"; mPrinter.addCut(Printer.CUT_FEED); } catch (Exception e) { ShowMsg.showException(e, method, mContext); return false; } textData = null; return true; } private boolean runPrintCouponSequence() { if (!initializeObject()) { return false; } if (!createCouponData()) { finalizeObject(); return false; } if (!printData()) { finalizeObject(); return false; } return true; } private boolean printData() { if (mPrinter == null) { return false; } if (!connectPrinter()) { return false; } PrinterStatusInfo status = mPrinter.getStatus(); dispPrinterWarnings(status); if (!isPrintable(status)) { ShowMsg.showMsg(makeErrorMessage(status), mContext); try { mPrinter.disconnect(); } catch (Exception ex) { // Do nothing } return false; } try { mPrinter.sendData(Printer.PARAM_DEFAULT); } catch (Exception e) { ShowMsg.showException(e, "sendData", mContext); try { mPrinter.disconnect(); } catch (Exception ex) { // Do nothing } return false; } return true; } private boolean initializeObject() { try { mPrinter = new Printer(((SpnModelsItem) mSpnSeries.getSelectedItem()).getModelConstant(), ((SpnModelsItem) mSpnLang.getSelectedItem()).getModelConstant(), mContext); } catch (Exception e) { ShowMsg.showException(e, "Printer", mContext); return false; } mPrinter.setReceiveEventListener(this); return true; } private void finalizeObject() { if (mPrinter == null) { return; } mPrinter.clearCommandBuffer(); mPrinter.setReceiveEventListener(null); mPrinter = null; } private boolean connectPrinter() { boolean isBeginTransaction = false; if (mPrinter == null) { return false; } try { mPrinter.connect(mEditTarget.getText().toString(), Printer.PARAM_DEFAULT); } catch (Exception e) { ShowMsg.showException(e, "connect", mContext); return false; } try { mPrinter.beginTransaction(); isBeginTransaction = true; } catch (Exception e) { ShowMsg.showException(e, "beginTransaction", mContext); } if (isBeginTransaction == false) { try { mPrinter.disconnect(); } catch (Epos2Exception e) { // Do nothing return false; } } return true; } private void disconnectPrinter() { if (mPrinter == null) { return; } try { mPrinter.endTransaction(); } catch (final Exception e) { runOnUiThread(new Runnable() { @Override public synchronized void run() { ShowMsg.showException(e, "endTransaction", mContext); } }); } try { mPrinter.disconnect(); } catch (final Exception e) { runOnUiThread(new Runnable() { @Override public synchronized void run() { ShowMsg.showException(e, "disconnect", mContext); } }); } finalizeObject(); } private boolean isPrintable(PrinterStatusInfo status) { if (status == null) { return false; } if (status.getConnection() == Printer.FALSE) { return false; } else if (status.getOnline() == Printer.FALSE) { return false; } else { ;//print available } return true; } private String makeErrorMessage(PrinterStatusInfo status) { String msg = ""; if (status.getBatteryLevel() == Printer.BATTERY_LEVEL_0) { msg += getString(R.string.handlingmsg_err_battery_real_end); } return msg; } private void dispPrinterWarnings(PrinterStatusInfo status) { EditText edtWarnings = (EditText)findViewById(R.id.edtWarnings); String warningsMsg = ""; if (status == null) { return; } if (status.getPaper() == Printer.PAPER_NEAR_END) { warningsMsg += getString(R.string.handlingmsg_warn_receipt_near_end); } if (status.getBatteryLevel() == Printer.BATTERY_LEVEL_1) { warningsMsg += getString(R.string.handlingmsg_warn_battery_near_end); } edtWarnings.setText(warningsMsg); } private void updateButtonState(boolean state) { Button btnReceipt = (Button)findViewById(R.id.btnSampleReceipt); Button btnCoupon = (Button)findViewById(R.id.btnSampleCoupon); btnReceipt.setEnabled(state); btnCoupon.setEnabled(state); } @Override public void onPtrReceive(final Printer printerObj, final int code, final PrinterStatusInfo status, final String printJobId) { runOnUiThread(new Runnable() { @Override public synchronized void run() { ShowMsg.showResult(code, makeErrorMessage(status), mContext); dispPrinterWarnings(status); updateButtonState(true); new Thread(new Runnable() { @Override public void run() { disconnectPrinter(); } }).start(); } }); } } 

can anyone suggest me where I can adjust the image size so that I print the page area and not the logo size ...

this is image data for image

 String method = ""; Bitmap logoData = BitmapFactory.decodeResource(getResources(), R.drawable.store); //I have given this Bitmap logoData = BitmapFactory.decodeResource(getResources(), R.drawable.full); 

and this is for the image content.

  method = "addImage"; mPrinter.addImage(logoData,0,0,logoData.getWidth(),logoData.getHeight(),Printer.COLOR_1,Printer.MODE_MONO,Printer.HALFTONE_DITHER,Printer.PARAM_DEFAULT,Printer.COMPRESS_AUTO); 

Please suggest how to print the contents of the image in full size ... I get the side of the page.

It should print 80 mm in size, but its 40 mm print can offer me how to make it full size or how to adjust the image size to stretch it to the maximum area of ​​paper ...

+6
source share
1 answer

Your question is a bit unclear.

I think your question is:

  • You are provided with image data with some resolution in the form of Android BitMapFactory.
  • You want to print on some printer with a different DPI. Android BitMapFactory is already installed.
  • You need to scale BitMapFactory for your logo.

Firstly, in your line for getting logo data, you can just try to examine the BitmapFactory.Options.inSampleSize parameter to get the right size. This will give you the best, but not perfect answer.

For perfect you should scale the logo. You can use the code here . See also related issues here and here .

0
source

All Articles