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();
}