2013-04-05 75 views
0

时,我有如下代码来获取截图getDrawingCache返回NULL运行猴

View screen = getWindow().getDecorView(); 
    screen.setDrawingCacheEnabled(true); 
    screen.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 
    screen.buildDrawingCache(); 

    Bitmap bitmap = screen.getDrawingCache(); 

的代码是onOptionsItemSelected在UI线程。

当我手动测试时,它运行良好。但是,当我用猴子运行该应用程序时,bitmapnull我不确定它是否始终为猴模式或只是偶尔因为猴子的随机性而为空。

任何想法,为什么猴子可以有不同的行为?我不想在后面的代码中盲目添加空指针检查器。

感谢

回答

0

你应该使用buildDrawingCache(真),因为buildDrawingCache()是一样的buildDrawingCache(假)。使一定要位图复制到使用getDrawingCache()像下面前另一个。

Bitmap bt=Bitmap.createBitmap(screen.getDrawingCache()); 

,因为它的拷贝回收之前我们的位图()如果调用setDrawingCacheEnabled(假)。