0
Bitmap bitmap;
View v1 = l1.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false); 

Doesn't work for me as:

bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 

Is causing a force close.

I'm using a LinearLayout

Darwind
  • 7,284
  • 3
  • 49
  • 48
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64

1 Answers1

0

You need to enable the drawing cache, if v1.getDrawingCache() is returning null. http://developer.android.com/reference/android/view/View.html#getDrawingCache(boolean)

levis501
  • 4,117
  • 23
  • 25
  • OP has in their sourcecode `v1.setDrawingCacheEnabled(true);` so it seems like this is not the issue. – FoamyGuy Apr 01 '13 at 19:32
  • From the doc:When hardware acceleration is turned on, enabling the drawing cache has no effect on rendering because the system uses a different mechanism for acceleration which ignores the flag. If you want to use a Bitmap for the view, even when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint) for information on how to enable software and hardware layers. – levis501 Apr 01 '13 at 19:33
  • I think this is for if you are creating your own view and overriding onDraw `enabling the drawing cache has no effect on rendering` When they say that I think they mean rendering onto the screen, not using getDrawingCache() I have used getDrawingCache() in the past with hardware acceleration on and had no issue. – FoamyGuy Apr 01 '13 at 19:45