如何将 Drawable 转换为位图? [英] How to convert a Drawable to a Bitmap?

查看:35
本文介绍了如何将 Drawable 转换为位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置某个Drawable作为设备的壁纸,但是所有的壁纸功能只接受Bitmaps.我无法使用 WallpaperManager 因为我是 2.1 之前的版本.

I would like to set a certain Drawable as the device's wallpaper, but all wallpaper functions accept Bitmaps only. I cannot use WallpaperManager because I'm pre 2.1.

此外,我的 drawable 是从网上下载的,并不位于 R.drawable 中.

Also, my drawables are downloaded from the web and do not reside in R.drawable.

推荐答案

这会将 BitmapDrawable 转换为 Bitmap.

This converts a BitmapDrawable to a Bitmap.

Drawable d = ImagesArrayList.get(0);  
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

这篇关于如何将 Drawable 转换为位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆