android - 在 android 中截取屏幕截图

标签 android screenshot

我想截取我的 Activity 和 Activity 组件( View )的屏幕截图。

此 Activity 包含一个 SurfaceView 和一个位于彼此顶部的布局。

当我截取 Surface view 的屏幕截图时效果很好,但是当我截取整个 Activity 的屏幕截图时,我无法在其中获取 Surface View。我正在使用以下代码:

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;
  }
}

最佳答案

解决方法是捕获布局 SurfaceView 图像,然后在布局图像上绘制SurfaceView 图像(使用 Canvas.drawBitmap) 在正确的坐标使用 SurfaceView 的属性。

关于android - 在 android 中截取屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11539421/

相关文章:

android - 以编程方式截取谷歌地图?

audio - 截屏时没有声音

c++ - 如何使用 xlib 正确截屏?

android - 如何诊断 Eclipse 中的 "Error executing aapt"错误?

android - 连接到远程数据库...在线数据库

javascript - Node中使用FFMPEG处理录屏的帧数

javascript - 用Java截取整个网页

java - 如何在单击 ViewPager 时打开详细信息 fragment ?

Android & WAMP : Error parsing data org. json.JSONException : Value <br of type java. lang.String无法转换为JSONObject

android - 如何清除 android 中谷歌地图中的所有 map 叠加层或标记?