我已经研究过找到解决方案来拍摄当前活动的快照,我找到了2个拍摄快照的解决方案,但是所有这些都无法帮助我找到我想要的正确的东西。
我的活动使用相机,我在该布局中显示3D对象(与AR相同,但不使用标记,只在相机框中绘制3D对象)。
因此,当我使用找到的解决方案时,我只获得父布局(RelativeLayout用于保存摄像机和3D对象)和其他一些对象(某个按钮),该位图与XML文件的物理设计屏幕相同。
我用这个解决方案来获取快照:
private Bitmap takeScreenShot(Activity activity)
{
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
view.destroyDrawingCache();
return b;
}
和这个解决方案:
public Bitmap snap() {
Bitmap bitmap = Bitmap.createBitmap(this.view.getWidth(), this.view.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
但我得到了同样的结果。
请帮我找到解决此问题的好方法。
感谢。