我尝试打印我的布局屏幕。我在位图中使用buildDrawingCache
,然后使用ByteArrayOutputStream
将其存储在外部存储器的文件中。现在,我想用wifi打印机打印它,但我不知道它是怎么做的。
活动(拍摄屏幕)
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++;
}
保存(在文件.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();
}