Android 2.1的视图的getDrawingCache()方法总是返回null [英] Android 2.1 View's getDrawingCache() method always returns null
问题描述
我的工作与Android 2.1,并具有以下问题: 使用方法View.getDrawingCache()始终返回null。 getDrawingCache()应该返回一个位图,这是查看的内容presentation。
例如code:
公共无效的onCreate(最终捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
最终的视图中查看= findViewById(R.id.ImageView01);
view.setDrawingCacheEnabled(真正的);
view.buildDrawingCache();
最后的BMP位= view.getDrawingCache();
的System.out.println(BMP);
}
我已经尝试了不同的方式来配置View对象生成图纸的高速缓存(如 View.setWillNotDraw(布尔)
和查看。 setWillNotCacheDrawing(布尔)
),但没有任何工程。
什么是正确的方式,或者是我做错了什么?
PS:在现实code我想申请getDrawingCache()像RelativeLayout的一个ViewGroup中。使用的ViewGroup时的行为一样?
位图的截图;
view.setDrawingCacheEnabled(真正的);
截图= Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(假);
您需要 Bitmap.createBitmap(view.getDrawingCache());
为getDrawingCache()<从中接收由引用的位图/ code>被回收。
I'm working with Android 2.1 and have the following problem: Using the method View.getDrawingCache() always returns null. getDrawingCache() should return a Bitmap, which is the presentation of View's content.
Example code:
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View view = findViewById(R.id.ImageView01);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
final Bitmap bmp = view.getDrawingCache();
System.out.println(bmp);
}
I've already tried different ways to configure the View object for generating the drawing cache (e.g. View.setWillNotDraw(boolean)
and View.setWillNotCacheDrawing(boolean)
), but nothing works.
What is the right way, or what I'm doing wrong?
PS: In real code I want to apply getDrawingCache() on a ViewGroup like RelativeLayout. Is the behaviour the same when using a ViewGroup?
Bitmap screenshot;
view.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
You need Bitmap.createBitmap(view.getDrawingCache());
as the Bitmap from which the reference is received by getDrawingCache()
gets recycled.
这篇关于Android 2.1的视图的getDrawingCache()方法总是返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!