getDrawingCache()始终返回null

Yug*_*abu 6 android screenshot

我想使用DrawingCache捕获ImageView的内容.我写了下面的代码.

iv1 = (ImageView)findViewById(R.id.iv1);
iv2 = (ImageView)findViewById(R.id.iv2);            
iv1.setDrawingCacheEnabled(true);
Bitmap myScreenshot = iv1.getDrawingCache();
iv2.setImageBitmap(myScreenshot);
Run Code Online (Sandbox Code Playgroud)

但我在屏幕上只得到一张图片.后来我才知道myScreenshot是空的

我看到很多关于同样问题的帖子,但没有适当的解决方案.

我认为我们必须在清单中添加任何权限?实现这一目标需要root权限?请帮我解决这个问题.

aqs*_*aqs 10

尝试buildDrawingCache()之前打电话getDrawingCache()

编辑:getDrawingCache()在页面加载后 调用,而不是onCreate