アクティビティとアクティビティ (ビュー) のコンポーネントのスクリーン ショットを撮りたいです。
このアクティビティには、互いの上に 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;
}
}