我想截取我的 Activity 和 Activity (View) 组件的屏幕截图。
这个 Activity 包含一个 SurfaceView 和一个相互叠加的布局。
当我截取 Surface 视图的屏幕截图时,它运行良好,但是当我截取整个 Activity 的屏幕截图时,我没有得到其中的 Surface 视图。我正在使用以下代码:
public class Screenshot {
private final View view;
/** Create snapshots based on the view and its children. */
public Screenshot(View root) {
this.view = root;
}
/** Create snapshot handler that captures the root of the whole activity. */
public Screenshot(Activity activity) {
final View contentView = activity.findViewById(android.R.id.content);
this.view = contentView.getRootView();
}
/** Take a snapshot of the view. */
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;
}
}