如何截取滚动视图的截图?

时间:2014-04-23 21:13:12

标签: android screenshot

如何截取特定布局的截图

此代码截取没有状态栏的活动的屏幕截图我想要进行滚动视图的屏幕

View view = getWindow().getDecorView();
            view.setDrawingCacheEnabled(true);
            view.buildDrawingCache(true);
            Bitmap b1 = view.getDrawingCache();
            Rect frame = new Rect();
            this.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
            int statusBarHeight = frame.top;
            int width = this.getWindowManager().getDefaultDisplay().getWidth();
            int height = this.getWindowManager().getDefaultDisplay()
                    .getHeight();

            Bitmap bm = Bitmap.createBitmap(b1, 0, statusBarHeight, width,
                    height - statusBarHeight);

我想截取滚动视图的截图 我在这里搜索了很多,但我发现任何人都无法帮助

2 个答案:

答案 0 :(得分:0)

你能截取包括标题栏的截图吗?

然后使用此Link

获取标题栏高度
DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int myHeight = 0;

    switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_HIGH:
            Log.i("display", "high");
            myHeight = display.getHeight() - 48;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            Log.i("display", "medium/default");
            myHeight = display.getHeight() - 32;
            break;
        case DisplayMetrics.DENSITY_LOW:
            Log.i("display", "low");
            myHeight = display.getHeight() - 24;
            break;
        default:
            Log.i("display", "Unknown density");

现在在你的代码中

替换

int height = this.getWindowManager().getDefaultDisplay()
                    .getHeight();

int height = this.getWindowManager().getDefaultDisplay()
                    .getHeight()-THE_HEIGHT_OF_NOTIFICATION_BAR;

我没有尝试过自己,但我想这会有效,看看它是从图像的顶部还是底部移除并让我们知道扫管笏发生...

THX

答案 1 :(得分:0)

'SELECT date FROM table WHERE date_format(date,'%Y-%m-%d') = "2017-01-08"'

注意:将ScrollView实例传递给此方法。