1

アクティビティとアクティビティ (ビュー) のコンポーネントのスクリーン ショットを撮りたいです。

このアクティビティには、互いの上に 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;
  }
}
4

3 に答える 3

1

回避策としてできることは、レイアウト画像の両方をキャプチャし、 のプロパティを使用して正しい座標で( を使用して) レイアウト画像の上に画像SurfaceViewを描画することです。SurfaceViewCanvas.drawBitmapSurfaceView

于 2012-07-18T10:56:15.460 に答える
0

これが役立つかどうかはわかりませんが、DDMS を使用して直接スクリーンショットを撮ることはできませんか?

編集

を取得して、そこから引き出すことができるビュー/画像キャッシュを確認してみましたかWindow?Activity

于 2012-07-18T10:48:03.087 に答える
0

それが役立つことを願って変更this.view = contentView.getRootView();します。this.view = contentView;

于 2012-07-18T10:42:58.487 に答える