如何转换LayerDrawable为位图? [英] How to convert LayerDrawable to Bitmap?
本文介绍了如何转换LayerDrawable为位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的为Android(这里的通用图像装载机是链接)
I'm using the Universal Image Loader for Android (here is the link)
我需要从一个URL加载图像并叠加到另一个图像。该库不能在默认情况下做到这一点,所以我试图改变它。
问题是,现在我需要一个LayerDrawable转换为位图。我该怎么做?
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?
推荐答案
只需绘制它是由一个位图支持的画布。
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);
这篇关于如何转换LayerDrawable为位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文