gpt4 book ai didi

android - 如何将 LayerDrawable 转换为位图?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:00 27 4
gpt4 key购买 nike

我正在使用适用于 Android 的通用图像加载器(这里是 link)

我需要从 URL 加载图像并将其覆盖到另一个图像。默认情况下图书馆不能这样做,所以我试着改变它。问题是现在我需要将 LayerDrawable 转换为位图。我该怎么做?

最佳答案

只需在由位图支持的 Canvas 上绘制即可。

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);

关于android - 如何将 LayerDrawable 转换为位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17897702/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com