getDrawingCache is not updated

99封情书 提交于 2019-12-05 17:50:54

I solved it. The problem was that I called setDrawingCacheEnabled(true) before the last draw operation on the canvas in onDraw. It must be called after you finished drawing, otherwise you won't get correct results.

Just to clarify, the problem here is that the View's drawing cache was not invalidated before the second time you call getDrawingCache().

In order for the drawing cache to be refreshed it must be invalidated and the order of call to the methods should be as follows:

public Bitmap renderView(View view) {
    view.setDrawingCacheEnabled(true)
    Bitmap bitmap = view.getDrawingCache();
    view.setDrawingCacheEnabled(false)
    return bitmap;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!