Android的 - getDrawingCache - 黑屏 [英] Android - getDrawingCache - black screen
本文介绍了Android的 - getDrawingCache - 黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读过pretty太多关于这个主题每一个岗位,但他们都不来帮忙。
I've read pretty much every post on this topic, but none of them seem to help.
我试图捕捉当前屏幕的截屏。对于这个我使用getDrawingCache。这里是我的code:
I'm trying to capture a screen shot of the current screen. For this I'm using getDrawingCache. Here's my code:
mRootView.get().setDrawingCacheEnabled(true);
mRootView.get().buildDrawingCache();
Bitmap screenShot = Bitmap.createBitmap(mRootView.get().getDrawingCache());
mRootView.get().setDrawingCacheEnabled(false);
生成位图始终是黑色的。
The resulting bitmap is always black.
mRootView是弱引用到抽屉布局,这是我的根视图。
mRootView is a weak-reference to the drawer layout, which is my root view.
下面是我已经试过:
- 添加度量和布局调用(尽管这不应该,因为当一个按钮pressed,所以认为应该已经奠定了这code运行时需要)。
- 设置图层类型调用之前LAYER_TYPE_NONE setDrawingCacheEnabled(真)
- 使用不同的视图为根视图(例如,在DrawerLayout内ViewPager)。
似乎没有任何工作,我已经江郎才尽了。
Nothing seems to work and I've run out of ideas.
推荐答案
您可以绘制视图的画布 -
You can draw your view to canvas-
通过主布局参考这个方法 -
pass your main layout reference to this method-
Bitmap file = save(layout);
Bitmap save(View v)
{
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
这篇关于Android的 - getDrawingCache - 黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文