Android get full View as Bitmap [duplicate]

浪尽此生 提交于 2019-12-30 11:13:10

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/7703227/android-get-full-view-as-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!