15

I use the code below to draw a view on to a bitmap/canvas.

Bitmap bitmap = Bitmap.createBitmap(
    viewGroup.getWidth (), viewGroup.getHeight (), Bitmap.Config.ARGB_8888);
viewGroup.draw(new Canvas(bitmap));

It works great, with one small problem: it doesn't draw elevation shadows. I assume that the shadows aren't drawn in the draw method. So where are they drawn and how can I transfer them to my canvas?

Ava
  • 2,038
  • 3
  • 23
  • 45

1 Answers1

7

No, shadows are drawn for Views at a lower level than that. You're using the software rendering pipeline which does not support shadows.

Chris Banes
  • 31,763
  • 16
  • 59
  • 50
  • 1
    Is there anyway to access this 'lower level'? – Ava Jun 21 '16 at 17:08
  • 2
    Any way around this @Chris ? – natario Oct 07 '17 at 17:25
  • This is a problem that has never seen a proper solution. To this day we still cannot easily convert a view to bitmap and keep its shadows, not even Pixel.copy api solved that, and the media projection option is not an option due to the consent prompt. – Shadow Apr 05 '21 at 06:12