3
我有這段代碼可以截取當前視圖,這是一個片段,它存在於一個活動中,活動只有一個背景。以編程方式拍攝整個屏幕的屏幕截圖
private File captureScreen() {
Bitmap screenshot = null;
try {
if (view != null) {
screenshot = Bitmap.createBitmap(view.getMeasuredWidth(),
view.getMeasuredHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(screenshot);
view.draw(canvas);
// save pics
File cache_dir = Environment.getExternalStorageDirectory();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.PNG, 90, bytes);
File f = new File(cache_dir + File.separator + "screen.png");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
return f;
}
} catch (Exception e) {
// TODO
}
return null;
}
但位圖保存不正是我所期待的。 截圖僅包含片段元素,但不包含活動背景。我如何將它包含在屏幕截圖中?
我建議你從這個問題得到幫助。 http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android – 2015-04-01 08:40:06