编辑:
没关系,让它这样工作
TopRatedPage.setDrawingCacheEnabled(true);
TopRatedPage.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
TopRatedPage.layout(0, 0, TopRatedPage.getMeasuredWidth(), TopRatedPage.getMeasuredHeight());
TopRatedPage.buildDrawingCache(true);
Bitmap screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache());
TopRatedPage.setDrawingCacheEnabled(false);
老的:
我正在尝试从布局中截取屏幕截图,就像这样。
LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null);
...
Bitmap screenshot;
TopRatedPage.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache()); // Caused by: java.lang.NullPointerException
TopRatedPage.setDrawingCacheEnabled(false);
任何想法我做错了什么?
谢谢!
编辑:也试过这样,它不会抛出错误,但给出一个空位图。
Bitmap screenshot = TopRatedPage.getDrawingCache();