Android screenshot from code. Got it but not perfect

前端 未结 6 552
攒了一身酷
攒了一身酷 2021-02-04 21:47

I\'m trying to take a screenshot in code in Android. Actually the screenshot is the bitmap of the main RelativeLayout. The screenshot is taken but the content appears wrong, the

6条回答
  •  借酒劲吻你
    2021-02-04 22:28

    Specify the screen size in makeMeasureSpec

    ...
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    v.measure(MeasureSpec.makeMeasureSpec(0, size.x),
                MeasureSpec.makeMeasureSpec(0, size.y));
    ...
    

    Also try setting the setDrawingCacheQuality to high, so that it returns a higher resolution bitmap.

提交回复
热议问题