Android screenshot from code. Got it but not perfect

前端 未结 6 554
攒了一身酷
攒了一身酷 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:04

    This works good for me:

    View content = findViewById(R.id.myElementForScreenshoot);
    View screenshot = content; // or content.getRootView() for fullscreen
    screenshot.refreshDrawableState();
    screenshot.setDrawingCacheEnabled(true);
    Bitmap b = screenshot.getDrawingCache();    
    

    After this you can process or save bitmap. Hope it helped. Cheers

提交回复
热议问题