Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make view.getDrawingCache() preserving transparency

Tags:

android

If I have a view with a transparent background and I do bitmap = view.getDrawingCache();, that bitmap is unfortunately no more transparent. A black background is set in background.

I have even tried

view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);

without success.

Actually this method allows to set the background color without any alpha support, Color.TRANSPARENT which is 0x00000000 is actually black if you don't care about the alpha part... If I use Color.RED, the background is indeed very red.

Any idea to make this work? Is this a limitation of current Android API? Can I use draw() instead? but it's less performant that this view.getDrawingCache() I suppose (no cache)?

Thanks

like image 349
gre Avatar asked Nov 27 '15 08:11

gre


1 Answers

I also get image with black background by calling getDrawingCache() method. Actually, the image has transparent background. Mistake is saving the image in jpeg format, so the gallery app shows transparent pixels in black color.

If you put it as an overlay, it'll work perfectly. There is no issue here.

like image 164
Minh Nguyen Avatar answered Nov 16 '22 17:11

Minh Nguyen