How to convert a Drawable to a Bitmap?

前端 未结 20 2500
攒了一身酷
攒了一身酷 2020-11-21 22:46

I would like to set a certain Drawable as the device\'s wallpaper, but all wallpaper functions accept Bitmaps only. I cannot use WallpaperMan

20条回答
  •  星月不相逢
    2020-11-21 23:19

    ImageWorker Library can convert bitmap to drawable or base64 and vice versa.

    val bitmap: Bitmap? = ImageWorker.convert().drawableToBitmap(sourceDrawable)
    

    Implementation

    In Project Level Gradle

    allprojects {
            repositories {
                ...
                maven { url 'https://jitpack.io' }
            }
        }
    

    In Application Level Gradle

    dependencies {
                implementation 'com.github.1AboveAll:ImageWorker:0.51'
        }
    

    You can also store and retrieve bitmaps/drawables/base64 images from external.

    Check here. https://github.com/1AboveAll/ImageWorker/edit/master/README.md

提交回复
热议问题