How to convert LayerDrawable to Bitmap?

爷,独闯天下 提交于 2019-12-10 14:44:46

问题


I'm using the Universal Image Loader for Android (here is the link)

I need to to load an Image from a URL and overlay it to another image. The library can not do it by default, so I'm try to change it. The problem is that now I need to convert a LayerDrawable to Bitmap. How can I do that?


回答1:


Just draw it on a Canvas which is backed by a Bitmap.

int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); 
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);


来源:https://stackoverflow.com/questions/17897702/how-to-convert-layerdrawable-to-bitmap

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