如何从表面视图创建和保存屏幕截图? [重复]

问题描述 投票:0回答:0

我有一个应用程序,我希望能够捕获屏幕截图

这是我的代码:

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的内容保存为black.!!!

请帮助我,谢谢...

android screenshot surfaceview
© www.soinside.com 2019 - 2024. All rights reserved.