getDrawingCache()总是返回nullgetDrawingCache、null

2023-09-05 02:06:00 作者:哀家要男宠三千

我想捕捉的ImageView的内容通过DrawingCache。我写了下面code。

I want to capture The content of ImageView by using DrawingCache. I written the below code.

iv1 = (ImageView)findViewById(R.id.iv1);
iv2 = (ImageView)findViewById(R.id.iv2);            
iv1.setDrawingCacheEnabled(true);
Bitmap myScreenshot = iv1.getDrawingCache();
iv2.setImageBitmap(myScreenshot);

不过,我收到只有一个在屏幕上的图像。后来我才知道的 myScreenshot 为null

我看到了关于同样的问题很多帖子,但没有妥善的解决方案。

I saw many posts regarding same problem, but no proper solution.

我认为我们必须在清单中添加任何权限?或者需要root权限来实现这一目标?请帮我有关这个问题。

I thought any permissions we have to add in manifest ? or root permission required to achieve this ? Please help me regarding this problem.

推荐答案

尝试调用 buildDrawingCache() getDrawingCache()

编辑: 呼叫 getDrawingCache()后,页面加载,而不是的onCreate

Call getDrawingCache(), after the page have loaded, instead of onCreate