0

I try to print a screen of my layout. I take it with buildDrawingCache in bitmap, then I store it in file on external memory with ByteArrayOutputStream. Now, I want print it with wifi printer but I don't know how do it.

Activity (take screen)

l.setBackgroundColor(Color.WHITE);
rl.setDrawingCacheEnabled(true);
rl.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
rl.layout(0, 0, rl.getMeasuredWidth(), rl.getMeasuredHeight());
rl.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(rl.getDrawingCache());
rl.setDrawingCacheEnabled(false);

if (i == 0) {
  Save.getInstance(getApplicationContext()).saveCards(bitmap);
  i++;
}

Save (in file .png)

File f = new File(localFile, "Cards_" + temp + ".png");
if (f.createNewFile()) {
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
   byte[] bitmapdata = bos.toByteArray();

   FileOutputStream fos = new FileOutputStream(f);
   fos.write(bitmapdata);
   fos.flush();

   fos.close();
}
K.Os
  • 5,123
  • 8
  • 40
  • 95
A. Ror
  • 17
  • 1
  • 7
  • 1
    Often the implementation details depends on the printer you want to use to print. BTW you can follow the official guide [here](https://developer.android.com/training/printing/index.html) to see if something there can be helpfull to you – MatPag Oct 03 '17 at 07:56
  • I see this official guide but I don't find something that help me. Also, I don't understand what you say, can you tell some example @MatPag? – A. Ror Oct 03 '17 at 08:05
  • What is the make and model of the printer you're using? This is important because different printers require different things. Somethings the manufacturer has documentation, sample code, or SDKs to make the development more straightforward – person Oct 13 '17 at 15:46

0 Answers0