Android

Android 利用Glide取得Bitmap 把Bitmap顯示為圓形背景

1.導入Glide

implementation 'com.github.bumptech.glide:glide:4.15.1'

2.聲明網路權限

<uses-permission android:name="android.permission.INTERNET"/>

3.取得Bitmap

 Glide.with(this)
      .asBitmap()
      .load("https://b.blog.xuite.net/b/b/5/2/11519069/blog_78644/txt/243420413/4.jpg")
      .into(object : CustomTarget<Bitmap>() {
           override fun onLoadCleared(placeholder: Drawable?) {}

           override fun onResourceReady(bitmap: Bitmap, transition: Transition<in Bitmap>?) {
               val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, bitmap)
               roundedBitmapDrawable.isCircular = true
               icon.setImageDrawable(roundedBitmapDrawable)
            }
})

4.效果展示

發表迴響