Android 获得完整的位图视图
我有一个布局,我想保存位图。
如果我的布局比屏幕小,一切都很好。但如果我的布局更大,则位图 (b) 为空。
这是我的代码:
layout.setDrawingCacheEnabled(true);
int wt = layout.getMeasuredWidth();
int ht = layout.getMeasuredHeight();
layout.layout(0, 0, wt, ht);
Bitmap b = layout.getDrawingCache(true);
那么如何才能将整个视图作为位图获取呢?
Possible Duplicate:
Android 2.1 View's getDrawingCache() method always returns null
I hava a Layout which I want to save an bitmap.
If my Layout is smaller than the screen everything is fine. But if my Layout is bigger, the bitmap (b) is null.
This is my code:
layout.setDrawingCacheEnabled(true);
int wt = layout.getMeasuredWidth();
int ht = layout.getMeasuredHeight();
layout.layout(0, 0, wt, ht);
Bitmap b = layout.getDrawingCache(true);
So how can I get the whole View as an Bitmap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 buildDrawingCache 不应该包含您的视图,因为它比屏幕大,因为仅绘制视图的可见部分,并且缓存仅保存绘制的内容。
你可以尝试一下这个方法。这里将位图传递给视图,以便将视图绘制到位图上。
http://www.brighthub.com/mobile/google-android/articles /30676.aspx
buildDrawingCache should not have your view if it is bigger than the screen as the visible portion of the view is only drawn and the cache holds only what is drawn.
You may try this method. Here a bitmap is passed to the view, so that the view is drawon to the bitmap.
http://www.brighthub.com/mobile/google-android/articles/30676.aspx