我想截取我的 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/